Parsing sizeof, strlen, pointers, and arrays as application of function parameters _c language

Source: Internet
Author: User
The code looks like this:
Copy Code code as follows:

typedef struct ST_TEST
{
int id;
Char *pname;
Char class[10];
}student;
VOID fn (Student *pstud) {
Pstud->id = 10;
Pstud->pname = "Tom simith";
strcpy (Pstud->class, "Class 1");
printf ("sizeof (Pstud) =%d/n", sizeof (Pstud)); sizeof (Pstud) = 4
printf ("sizeof (pstud->id) =%d/n", sizeof (Pstud->id)); sizeof (PSTUD->ID) = 4
printf ("id:%d/n", pstud->id); Id:10
printf ("sizeof (pstud->pname) =%d/n", sizeof (Pstud->pname)); sizeof (pstud->pname) = 4
printf ("strlen (pstud->pname) =%d/n", strlen (Pstud->pname)); strlen (pstud->pname) = 10
printf ("name:%s/n", pstud->pname); Name:tom Simith
printf ("sizeof (pstud->class) =%d/n", sizeof (Pstud->class)); sizeof (Pstud->class) = 10
printf ("strlen (pstud->class) =%d/n", strlen (Pstud->class)); strlen (Pstud->class) = 7
printf ("class:%s/n", Pstud->class); Class:class 1
}
void Fnarray (char arr[]) {
printf ("arr:%s/n", arr); Arr:hello
printf ("sizeof (arr) =%d/n", sizeof (arr)); sizeof (ARR) = 4 the length of pointer
printf ("strlen (arr) =%d/n", strlen (arr)); strlen (arr) = 5 The length of array
}
int main (int argc, char **argv)
{
Student Stud;
FN (&stud);

Fnarray ("Hello");
return 0;
}

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.