Global Variables in C Programming With Example

Definition Of Global Variable

Auto Variable defined with auto storage class are local to the function block inside which they are defined. The variables which are declared inside a block are known as automatic or local variables; these variables allocates memory automatically upon entry to that block and free the occupied memory upon exit from that block.

Keyword 'auto' may be used to declare automatic variable but we can declare these variable without using 'auto' keywords.

The keywords auto is not required to be prefixed to each variable as local variables belong to the auto class.

Example:



Output:


 sum is : 8

Here, 'a' and 'b' are global variables. Because they are declared out side of the function

Example 2:



Output:


  3 2 1 
 

Read Also,