[C language-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 searching from the nearest scope until you find the variable

#include <stdio.h>int main (int argc, const char * argv[]) {    int a = +;       {        int a = $;        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. C Language Variable memory Analysis C language addressing from large to small
1 #include <stdio.h> 2  3 int main (int argc, const char * argv[]) {4     int a =; 5     int b = n; 6     7     printf ("The address of A is%d\n", &a); 8     printf ("The address of B is%d\n", &b); 9     return 0;1 1}
Out The address of A is 1606416268
The address of B is 1606416264
-"4 bytes apart, from big to small

[C language-2] C Language Variables

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.