Program --- C language details 22 (Precautions for returning the pointer to the function (floating pointer), view the memory size that can be allocated by the process)
Main Content: Precautions for returning pointers to Functions <Floating pointer> View the memory size that a process can allocate
# Include
Char * favorite_fruit () {static char fruit [] = "apple"; // If static is not added, the pointer returned by this function is left blank, because when the function exits, the number of fruit groups is destroyed // After static is added, the fruit array is allocated in the Data Segment, instead of in the stack. The life cycle is as long as that of the program, return fruit;} int main () {char * a = favorite_fruit (); printf ("% s \ n", ); /** view how much memory your process can allocate * The total amount of memory allocated depends on the System Configuration */int MB = 0; while (malloc (1 <10 )) + KB; printf ("Allocated % d KB total \ n", KB); return 0 ;}
Output: