C Language

Variable initialization and declaration in C

In C Language by Baqir AliLeave a Comment

Before using a variable in our program we must notify the compiler about that variable via declaration. like the example below

 int upper;
 int step;
 char a;
 char b; 

Variables with the same type can be grouped together:

int lower, upper, step; 
char a, b;  

Initializing Variables

C allows variables to be initialized in the declaration statement. The following statement declares the integer variable count and initializes it to 0.

int count=0;

Example 1:

#include<stdio.h>
void main(void)
{
   int a=10;
   //the above line declares variable a and assigns value 10 to it
   printf("value of a is %d",a);
}

Output is:

value of a is 10

Variable Initialization and Declaration

Support us by sharing this post

Leave a Comment