• 局部变量和static变量的区别


    	static int a ;
    	int b;
    	scanf_s("%d %d",&a,&b);
    01374212  lea         eax,[b]  
    01374215  push        eax  
    01374216  push        offset a (0137A13Ch)  
    0137421B  push        offset string "%d %d" (01377BCCh)  
    01374220  call        _scanf_s (0137137Fh)  
    01374225  add         esp,0Ch  
    	printf("%d",a);
    01374228  mov         eax,dword ptr [a (0137A13Ch)]  
    0137422D  push        eax  
    0137422E  push        offset string "%d" (01377BD4h)  
    01374233  call        _printf (01371375h)  
    01374238  add         esp,8  
    	printf("%d",b);
    0137423B  mov         eax,dword ptr [b]  
    0137423E  push        eax  
    0137423F  push        offset string "%d" (01377BD4h)  
    01374244  call        _printf (01371375h)  
    

      

    根据汇编代码可以看到,局部变量的地址是在栈中,而static变量的地址是在全局变量区里面。

  • 相关阅读:
    155. 最小栈
    160. 相交链表
    PAT 1057 Stack
    PAT 1026 Table Tennis
    PAT 1017 Queueing at Bank
    PAT 1014 Waiting in Line
    PAT 1029 Median
    PAT 1016 Phone Bills
    PAT 1010 Radix
    PAT 1122 Hamiltonian Cycle
  • 原文地址:https://www.cnblogs.com/yfish/p/9665774.html
Copyright © 2020-2023  润新知