Local Variables in C : A Step-by-Step Guide


In C programming, a local variable is a variable that is declared within a function or a block of code. Local variables are only accessible within the scope of the function or block in which they are declared, and they are not visible to other parts of the program. They are also known as automatic variables or stack variables.

The basic syntax for declaring a local variable in C is as follows:

           data_type variable_name ;

Here, the data_type specifies the data type of the variable, and the variable_name is the name of the variable.

Here is an example of a local variable being used in a function:

Source Code

//Local Variable
 
#include<stdio.h>
 
int add()
{
    int a,b;
}
 
int main()
{
    for(int i=0;i<5;i++)
    {
        printf("\n%d",i);
    }
     //printf("\n%d",i);
    return 0;
}
 
To download raw file Click Here

Output

0
1
2
3
4

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C