Variable location in memory

 

Global variables and local variables
scope
global variables
1, where the role of the module.
2, in the PE structure, the global variable is located .data section
3, the immediate addressing.

Local variables
1, where the function and scope of the same.
2, where the address on the stack.
3, is addressed by EBP or ESP.

 

#include " pch.h " 
#include <the iostream>
 #define CONST 888 int gint = 666 ; int main () 
{ / * 
    this is the constant folding in C ++: const variable means (i.e., constant) value in a compiler symbol table, when the values calculated directly from the compiler table, 
    eliminating the memory access time, so as to achieve optimization. 
    And on this basis, coupled with volatile modifier that tells the compiler that the variable part of fickle, do not optimize this sentence, 
    go fetch the amount of memory each time the calculation. 
    There is also a small detail: modification of each compiler volatile modifier inconsistent results, and some direct "ignore" * / const volatile int A = 12345 ;
     int * the p-= ( int *) & A ;
     * the p-= 456 ;
     const char




    


    
        *cp = "linux";
    //*cp = "L"; 报错
    printf("a = %d\n",a);

    int lint = 555;
    printf("lint = %d ,gInt = %d\n", lint, gInt);

    std::cout << "Hello World!\n"; 
    system("pause");
}

 

Guess you like

Origin www.cnblogs.com/xiangtingshen/p/11368512.html