C language--structure function parameter

Source: Internet
Author: User

Do ICMP attack want to take IP as user input, suddenly found themselves even transfer structure parameters are not, this is first from small program test, figure out later can proceed.

First, passing struct variables:

#include <stdio.h>structpara{Char*A;intb;};voidPrintstructpara f) {printf ("a=%s\nb=%d\n", f.a,f.b);}voidMain () {structpara p; P.a="ABC"; P.B= A; Print (P);}

Second, passing struct-body pointers:

#include <stdio.h>structpara{Char*A;intb;};voidPrintstructPara *f) {printf ("a=%s\nb=%d\n",f->a,f->b);}voidMain () {structpara p; P.a="ABC"; P.B= A; Print (&p);}

If you define a struct pointer, you must first allocate space for it, otherwise the value assigned later is not stored. Assign with malloc and remember to add a header file.
However, the struct pointer refers to the struct member, the symbol is used.

#include <stdio.h>#include<stdlib.h>structpara{Char*A;intb;};voidPrintstructPara *f) {printf ("a=%s\nb=%d\n",f->a,f->b);}voidMain () {structPara *p; P=(structpara*) malloc (sizeof(structpara)); P->a="ABC"; P->b= A; Print (P);}


This seems to be a freshman study of the content, are graduating quickly unexpectedly forget, are embarrassed to say that they are computer professional ...

C language--structure function parameter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.