[Learning notes] [C Language] variable type, learning notes variable

Source: Internet
Author: User

[Learning notes] [C Language] variable type, learning notes variable

According to the scope of the variable, it can be divided:
1. Local variables:
1> definition: variables defined within a function (code block) (including the form parameters of the function)
2> scope: Starting from the line that defines the variable until the end of the code block
3> lifecycle: the bucket is allocated from the row where the variable is defined. After the code block ends, it is recycled.
4> no Fixed Initial Value
 
2. Global Variables
1> definition: variables defined outside the Function
2> scope: starts from the line that defines the variable and ends with the end of the file (can be shared by all functions below)
3> life cycle: Once a program is started, it will allocate storage space, and the program will be destroyed only when it exits.
4> the default initial value is 0.

1 // global variables: a, B, c 2 // local variables: v1, v2, e, f 3 4 # include <stdio. h> 5 // The initial value of variable a is 10 6 int a = 10; 7 8 // The initial value of variable B is 0 9 // The initial value of variable c is 2010 int B, c = 20; 11 12 int sum (int v1, int v2) 13 {14 return v1 + v2; 15} 16 17 void test () 18 {19 B ++; 20 21 int I = 0; 22 I ++; 23 24 printf ("B = % d, I = % d \ n", B, I ); 25} 26 27 int main () 28 {29 test (); 30 test (); 31 test (); 32 33 int e = 10; 34 35 {36 {37 int f = 30; 38} 39} 40 41 return 0; 42}

 

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.