Variables 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:

  • local variable
  • global variable
  • static variable
  • external variable
  • 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.

Watch this C Programming and Data Structure Video by Intellipaat:

Variables and Constants in C

Youtube subscribe

Constants in C

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:

  • Primary Constants
  • Secondary Constants

C 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

Certification in Full Stack Web Development

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

Recommended Videos

Leave a Reply

Your email address will not be published. Required fields are marked *