Goto,void,extern,sizeof Analysis

Source: Internet
Author: User

Goto:

The quality of the program is inversely proportional to the number of Goto occurrences, disabling

Goto side Effects: The process of executing the program in a structured sequence, it is possible to skip some steps that should be performed by the program.

void

modifier function return values and parameters

The size of void's memory space is not defined in the C language, and it is not possible to crop void-corresponding variables in memory, but different compilers may have defined the size of the memory space for that data type, and the standards are inconsistent.

printf ("%d\n", sizeof (void)), the result of execution in different compilers, the result may be different.

void*:

Used as an lvalue to receive pointers of any type

When assigning to other types of pointers as rvalue, you need to force type conversions

int* pi= (int*) malloc (sizeof (int.));

void* Pc1=pc2=null;

Pc1=pi;

Pi= (int*) PC1; Correct wording

PI=PC2; Some compilers may be able to pass, but in terms of the syntax structure, the compiler is not prescriptive enough.

1 //*******test4.c********2 void* My_memset (void* p,CharVintsize)3 {4   void* ret=p;5   intI=0;6   Char* Dest= (Char*) p;7    for(i=0; i<size;i++)8   {9dest[i]=v;Ten   } One   returnret; A } -  - intMain () the { -   intabc[5]={1,2,3,4,5}; -My_memset (ABC,0,sizeof(ABC)); -    for(intI=0;i<5; i++) +printf"%d\n", Abc[i]); -   return 0; +}

The parameter void* p in the function indicates that pointers to all types of variables can be accepted, which is the benefit of void*.

extern is used to declare an externally defined variable or function, externally as defined in another file, and after it is declared in a file, this function can be called or used:

extern int ABC;

extern int func (int a,int b);

The second function: used to tell C compiler to compile with C-mode.

extern "C"

{

int add (int a,int b)

{

return a+b;

}

}

sizeof is the compiler's built-in indicator, not a function, the amount of memory used to "calculate" the corresponding entity, and the value of sizeof is determined at compile time:

INT ABC;

sizeof (a), sizeof (int)

printf ("%d\n", sizeof (a)); 4

printf ("%d\n", sizeof a); 4

printf ("%d\n", sizeof (int)); 4

Goto,void,extern,sizeof Analysis

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.