Anonymous strings and return values in C language

Integrated initialization of C language arrays and structures:
Example: int a[10]={};
Integrated initialization of the elements of the array If no initial value is given, the default initialization is 0
. The structure can also use integrated initialization. Like the array, the initial value not given is filled with 0 by default.

int a[10] = 1; Some compilers do not report an error, but this statement has no effect

Character array initialization:
Example: char c[10]="abc";
Elements without initial values ​​will be initialized by default. 0, that is, the following blank characters are filled with 0 by default

Global variables and static variables will also be initialized to 0 by default.

In the compiler, the string literal will be placed in an "anonymous" character array, and the saved location is located in the code section of the program (a section of memory in the program, the memory of a C program will allocated into several sections for saving different variables), and returns an address. If the same string literal appears in the code, the compiler will return the same address
char *s=" ;";
char *ss="";
These two pointers store the same address value, or the two pointers point to the same variable

int* f(){ int a: return &a; }f()=5 ;.//Access variables through the address of the return value In fact, the variable a here is released when the f function is executed. The read data may be garbage values, which is ignored here. Vulnerability If the function return value is a pointer type, the address value will be returned. The exception is that you can directly use the f() method to access the variable at the address.





Guess you like

Origin blog.csdn.net/qq_38022367/article/details/114631568