C language code [version] finding fault find, you can find out the problem?

       Ladies and gentlemen, today to see someone write below this piece of code, let us look out, look for the problem:

       Remember in front of the push we seem to have said similar problems, in fact, this topic if the C language solid foundation, then one will see the problem: the pointer p points to a string constant abc, abc stored in memory at a time of constant region , read-only, and the third line of code to modify the contents of read-only sections of intent , and therefore it is clear error.

       As mentioned in a C program storage problem, it would want to repeat a few words, which is why we want to tell you the main point of today's knowledge:

A compiled C program memory occupied divided into the following sections:

      1, the stack area (Stack) -, also known as automatic type storage area allocated by the compiler automatically release the stored function parameters, local variables, and the like, for example, is automatically released after the end of the function call.

      2, the heap (heap) region - also known as dynamically allocated memory area allocated by the programmer is released from the distribution until the end of the program, if not released, the program may be provided by the end of the recovery OS, such as malloc allocate memory, free memory release .

      3, the global zone (quiescent zone) (static) - global variables and static variables are stored in one and initialized global and static variables in an area, uninitialized global variables and static variables uninitialized adjacent another piece of the region, after the end of the program released by the system.

      4, literals region  - constant string on here, is released by the end of the program system.

      5, the program code area  - the program compiled code placed here.

       We want to help, do not step on the pit, thanks for your patience to read!

       For those who love programming, there are a group of small partners together to learn is very important! If you are interested or in need, then we have a zero-based introductory programming learning exchange clubs , as well as learning video files, are welcome beginners and advanced in little friends!

Published 520 original articles · won praise 132 · views 80000 +

Guess you like

Origin blog.csdn.net/HUYA69/article/details/105139567