Description

 

Variable is used for store the data. A variable is a name of the variable location where the variable is stored. The value of variable can be changed, and variable reused many times. It is the way to represent the location of the value which that can be easily identified.

Syntax of Declared Variable

type variable_name;

For example :

int var1;
float var2;

Here var1 and var2 are the variables. and here the int and float are datatypes.

We can delcared the variable like that

int a = 10, b = 90; // Declared two variable of integer datatypes

We can provide the value at the time of declaration.

Rules of Declaration Variable

  • A variable starts with the  alphabets and underscore.
  • A variable can not start with number and any digits.
  • No white space allowed to declare the variable in c programming language.
  • Variable can have alphabets , number, underscore also.

For Example :

int var; // Valid 
int _var; // Valid
int var_;  // Valid
int var1; // Valid
int 1var; // Invalid
int var 1; // Invalid

Types of Variables in C

There are many types of variables in c programming lanuguage :

  1. Local Variable
  2. Global Variable
  3. Static Variable
  4. Automatic Variable
  5. External Variable

Local Variable :

A variable is called Local Variable, that is decalred inside the function. which Variable is Accessable that function where variable decared, means the this variable is not used to other function.

For Example : 

void fun(){
    int var = 10;  // This is Local Variable. Because this variable existance only this function.
}

Global Variable : 

A Variable called Global Variable, that is declared outside the function. which accessable whole program. We can used the global variable in function and more times. Any function change the value of global variable.

For Example :

int var = 10; // Global Variable
void fun(){
    int var1 = 23; // Local Variable
}

Static Variabel :

A variable that is declared with the static keyword is called static variable. It retains its value between multiple function calls.

For Example :

void fun(){
    int x = 20; // Local Variable
    static y = 10; // Static Variable
    x = x + 1;
    y = y + 1;
    printf("The value of x is %d and the value of y is %d \n",x,y);
}

If you call this function many time the value of x is same every time but the value of y is change by one every time. The local variable will print the the same value for each function called, but the static variable will print the incremented valeu in each function call.

Automatic Variable :

All variable in c that declared inside the function is automatic variable by default. We can explicitly declare an automatic variable using auto Keywords.

void fun(){
    int var = 10; // local variable (automatic variable also)
    auto int y = 89; // Automatic Variable

Data types specifies the type of data that the variable can store the value such as integer, floating, character, double etc.

More types of Datatypes

 

Types Dataypes
Basic Data type int, char, float, double
Derived Data type array, pointer, structure, union
Enumeration Data type enum
Void Data type void

Keywords is reserved word in c programming language. You can not use keywords as a variable. There are only 32 keywords in c programming language. All Keywords is Below...

 

auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
defualt goto sizeof volatile
do static if while

 

Comments

Login is mandatory to comment Please login

 Akash Kumar

Comment : Nice Post!!👍👍

Recommended Posts

Operators | Type Conversion | Precedence | Associativity | in C programming language

What s operator in c programming language. How many types of Operators. What is conversion in c programming language. Precedence and Associativity of operators.

Control Statement in C | if statement | switch case

What is control statement in c. What is if statement? how to work switch case statement in c programming language? What is loops? Types of loops?

Loops in c | for loop | while loop | do while loop | c programming language

Welcome Guys.. What is loop and how many types of loops in c programming language. How loops work in c programming language.

Array in c programming language

An Array is the list of finite number of elements of same data types. For Example: interger, string, float etc. An Array can be defined as the collection of the

Break and Continue Statement in c

Break statement is usually used to terminate a case in the switch statement. In c programming language the continue statement works...

Function in C | What is Functions?

Function like main(), printf() and scanf(), we have already come through. All c Programs made up of one or more function.