Flat 10% & upto 50% off + Free additional Courses. Hurry up!

Variable and Constant in C


Variable is used to store the value. As name indicates its value can be changed or also it can be reused many times.


Data type variable_name;


int a;

Where a is the variables.

There are many types of variables in c:

  1. local variable
  2. global variable
  3. static variable
  4. external variable
  5. Automatic variable


1. Local variable – A variable which is declared inside the function is known as local variable. It is used only inside the function in which it is declared.

2. Global variable – A variable which is declared outside the function is known as global variable. It can be used throughout the program.

3. Static variable – It is used to retain its value between multiple function calls. It is declared using static keyword.

4. External variable – You can share a variable in multiple C source files by using external variable. It is declared using extern keyword.

5. Automatic variable – Variable which is declared inside the block is known as automatic variable by default.


Constant –Its value is fixed throughout the program that means constants are those variables which value is not changed throughout the program.

C constants can be divided into two major categories:

  1. Primary Constants
  2. Secondary Constants


There are two simple ways in C to define constants:

1. Using#define 


#include <stdio.h>

#define value 10

void main() {

int data;

data = value*value;

printf("value of data : %d",data);



value of data : 100

2. Using const keyword


#include <stdio.h>

void main() {

const int  value = 10;

int data;

data =value*value;

printf("value of data : %d",value);



value of data : 100

"0 Responses on Variable and Constant in C"

Training in Cities

Bangalore, Hyderabad, Chennai, Delhi, Kolkata, UK, London, Chicago, San Francisco, Dallas, Washington, New York, Orlando, Boston

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.


Sales Offer

  • To avail this offer, enroll before 10th December 2016.
  • This offer cannot be combined with any other offer.
  • This offer is valid on selected courses only.
  • Please use coupon codes mentioned below to avail the offer

Sign Up or Login to view the Free Variable and Constant in C.