2. C Language Variables

Source: Internet
Author: User
Tags variable scope

A. Variable scope: 1. Local variables: variable scopes defined inside a function or code block: from definition to the end of code block lifecycle: Assign a control from a definition, and then recycle a local variable without a default value after the code block ends, and initialize 2 yourself. Global variables: variable scope defined outside the function: from the definition to the end of the file (can be shared by all subsequent functions) life cycle: The program starts allocating space, the program exits the recycle global variable has a default value of 0 start from the nearest scope until you 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
Suitable use of blocks, can improve performance, in a timely manner to reclaim the variables defined in the memory block after execution will be recycled B. Memory analysis of C language Variables C language addressing from large to small # include <stdio.h>

int main (int argc, const char * argv[]) {
int a = 100;
int b = 200;

printf ("The address of A is%d\n", &a);
printf ("The address of B is%d\n", &b);

return 0;
} out: The address of A is 1606416268
The address of B is 1606416264
-"4 bytes apart, from big to small

2. C Language Variables

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.