In this lesson, we are discussing variable declaration in C language. Before assigning values to the variables, we must declare variables.
Variable Declaration in C
When we declare variables in C programming, it specifies the type of data values that the variable will hold and it tells the name of the variable to the compiler.
The syntax for Declaring Variables
data_type variable_name;
Examples
int mark; float ratio;
In C programming we can declare more than one variables of the same datatype at a time.
Examples
int variable1, variable2, variable2;
Assigning Values to Variables
Data values are assigned to the variables as follows:
variable_name = data_value;
Examples
mark = 5; c = 'a';
Data values can also be assigned to the variables at the time of variable declaration.
Assigning Values to the Variables at Declaration Time
int a = 5; char c = 'a';
Example Program
#include void main() { int mark; mark = 60; if(mark>40){ printf("You Have Passed the Examination"); } }