[C language, C Language

Source: Internet
Author: User

[C language, C Language
A. variable scope: 1. local variables: the scope of variables defined within a function or code block: from the definition point to the end of the code block lifecycle: allocate controls from the definition point. After the code block ends, the collected local variables do not have default values, initialize it by yourself. global variables: Scope of variables defined outside the function: from the definition point to the end of the file (can be shared by all subsequent functions) lifecycle: Allocate space for program startup, the program exits and recycles global variables. The default value is 0.

From the latest scope to find the variable

# Include <stdio. h> int main (int argc, const char * argv []) {int a = 100; {int a = 200; printf ("a = % d \ n ", a);} printf ("a = % d \ n", a); return 0 ;}
Out: A = 200
A = 100
It is suitable for block usage, which can improve performance. After the execution of the variables defined in the memory block is recycled in a timely manner, B. Memory Analysis of C language variables C language addressing from large to small
1 # include <stdio. h> 2 3 int main (int argc, const char * argv []) {4 int a = 100; 5 int B = 200; 6 7 printf ("The address of a is % d \ n", & a); 8 printf ("The address of B is % d \ n", & B ); 9 10 return 0; 11}
Out: The address of a is 1606416268
The address of B is 1606416264
-4 bytes different from large to small

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.