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

Memory arrangement of variables in C language

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

There was some confusion about the arrangement of C variables in memory, so the following aspects were briefly sorted out (all examples are compiled based on GCC on X86 PC Ubuntu).

The increasing direction of memory addresses allocated to different variables when defining variables

(1)Define two global variables, print their allocated addresses in memory after assignment compilation, and find that the variables defined first are allocated in the lower addresses in memory.

(2)X86 PC Ubuntu main function defines variables, use gcc compilation to check the memory address allocated by the system to variables (memory allocation growth direction is low address to high address)

The direction in which memory addresses allocated to members of a structure grow after instantiation of the structure

(1)Define the global structure and initialize it. After gcc compilation, view the growth direction of memory allocation of structure members (the growth direction of memory allocation is from low to high)

(2)In the main function for the structure and initialization, gcc compiled to view the structure member memory allocation growth direction (memory allocation growth direction is from low to high upward growth)

The memory growth direction of the stack space used when defining variables in functions

arm When using arm cross-compiling tool chain, the memory allocation of general variables is upward growth direction, but for the memory allocation on the stack, the full stack reduction method is used to allocate memory on the stack to variables, and the growth direction of the stack is downward growth direction.

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

Wechat

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

12
Report