Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the storage area of C++?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "what is the storage area of C++?". In the operation of practical cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In the program development, we divide the C++ storage area into the following steps:

1, stack area (stack)-automatically allocated and released by the compiler, storing the parameter values of the function, the values of local variables, etc. It operates in a manner similar to the stack in the data structure.

2. Heap-generally allocated and released by programmers, if the programmer does not release, the program may be reclaimed by the system at the end of the program. Note that it is different from the heap in the data structure, but the allocation method is similar to the linked list.

3. Global area (static zone) (static)-the global and static variables are stored together, the initialized global variables and static variables are in the same area, and the uninitialized global variables and uninitialized static variables are in the adjacent area. Released by the system at the end of the program

4. The text constant area-the constant string is put here. Released by the system at the end of the program

5. Program code area-the binary code that stores the body of the function.

Local variables in the C++ storage area can be initialized with any expression that matches the type.

Global variables can only be initialized with constant expressions (Constant Expression).

For example, the global variable pi is legally initialized like this:

Double pi = 3.14 + 0.0016

But this initialization is illegal:

Double pi = acos (- 1.0)

If the global variable is not initialized at definition time, the initial value is 0, and if the local variable is not initialized at definition time, the initial value is uncertain.

Therefore, the local variables in the C++ storage area must be assigned before use, if the subsequent calculation based on an uncertain value will certainly introduce Bug.

This is the end of the content of "what is the storage area of C++"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report