Programmer --- C language details 29 (# define grand and small, empty struct size, flexible array I don't know if you have seen it)

Source: Internet
Author: User

Programmer --- C language details 29 (# define grand and small, empty struct size, flexible array I don't know if you have seen it)
Main Content: # define large and small, empty struct size, flexible array

I. # define grand and small

See examples

Ii. Empty struct size

Related to the root Compiler

3. Flexible Array

Not commonly used.

# Include

 
  
# Define N 4 # define STR "abcd" int main () {struct student {} stu; printf ("N = % d \ n", sizeof (N )); printf ("num 5 memery = % d \ n", sizeof (5); printf ("char 'D' = % d \ n ", sizeof ('D'); printf ("STR = % d \ n", sizeof (STR); printf ("a = % d \ n ", sizeof (stu); // output 0 in gcc and mingw5 compiler, and 1 in vc ++ 6.0 (My mingw5 compiler ), in vc ++ 6.0, the minimum size of the struct is 1 byte by default (contains an empty struct and only contains one char struct) /* for flexible array testing, refer to deep anatomy of C language */printf ("\ n flexible array testing \ n"); typedef struct test {int I; int a []; // This array must contain another member} te; printf ("sizeof (te) = % d \ n", sizeof (te )); // int a [] is not a member of the struct te * p = (te *) malloc (sizeof (te) + sizeof (int) * 100 ); p-> a [0] = 13; printf ("p-> a [0] = % d \ n", p-> a [0]); printf ("sizeof (p) = % d \ n", sizeof (p); // The size is still 4, because int a [] is not a member of the struct, return 0 ;}

 

Output:


Related Article

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.