Variables in C

A variable is a name of memory location. It is used to store data. Its value can be changed and it can be reused many times.


Syntax to declare a variable in C

data_type  variable_name = value ;


#include <stdio.h>
#include <conio.h>
int main()
{
    int a=56;//declaring and initializing the variable
    int b=65;//declaring and initializing the variable
    printf("value of a is %d",a);
    printf("\n");
    printf("value of b is %d",b);
    return 0;
}
value of a is 56
value of b is 65

If no input values are assigned by the user than system will gives a default value called garbage value.

Rules for defining variables

To Declare any variable in C language you need to follow rules and regulation of C Language, which is given below.

  A variable can have alphabets, digits and underscore.

  A variable name can start with alphabet and underscore only. It can't start with digit.

  No white space is allowed within variable name.

  A variable name must not be any reserved word or keyword e.g. int, float,double,byte etc.

Garbage value

Garbage value can be any value given by system and that is no way related to correct programs. This is a disadvantage of C programming language and in C programming it can overcome using variable initialization.


#include <stdio.h>
int main()
{
    int a;//declaring 
    int b;//declaring 
    printf("value of a is %d",a);//printing Garbage  value 
    printf("\n");
    printf("value of b is %d",b);
    return 0;
}
woman avatar