









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










2026 Edition
Variables and constants are fundamental elements of the 'C' programming language used to store data in a program. Variables are named memory locations whose values can change during program execution, while constants represent fixed values that do not change during execution. Understanding variables and constants is essential for performing calculations, processing data, and controlling program behavior. In 'C', variables and constants must be used according to specific rules related to their data types, declaration, initialization, scope, and lifetime.
•The syntax to declare a variable in 'C' specifies the name and the type of the variable. data_type variable_name = value; // defining single variable or data_type variable_name1, variable_name2; // defining multiple variable Here,
2026 Edition
There are 3 aspects of defining a variable: 1.Variable Declaration 2.Variable Definition 3.Variable Initialization
'C' Variable Declaration Variable declaration in 'C' tells the compiler about the existence of the variable with the given name and data type. No memory is allocated to a variable in the declaration. 'C' Variable Definition In the definition of a 'C' variable, the compiler allocates some memory and some value to it. A defined variable will contain some random garbage value till it is not initialized. int var; char var2; Most of the modern 'C' compilers declare and define the variable in single step. 'C' Variable Initialization Initialization of a variable is the process where the user assigns some meaningful value to the variable. int var; // variable definition var = 10; // initialization or int var = 10; // variable declaration and definition
Following are the rules to assign any name to the variable
2026 Edition
Valid Names
_name, first_name
nameIIsem,
Name_2sem
Invalid Names
First name
34name
goto, for, switch
It contains a whitespace between First and name
Starting with a number
Can’t declare them variable as they are keywords
The 'C' variables can be classified into the following types: 1.Local Variables 2.Global Variables 3.Static Variables 4.Automatic Variables 5.Extern Variables 6.Register Variables
•The constants in 'C' are the read-only variables. •Its value cannot be modified once they are declared in the 'C' program. •The type of constant can be an integer constant, a floating pointer constant, a string constant, or a character constant •constant in 'C' language is always declared using the const keyword. •It is also known as a const type qualifier , the const keyword is placed at the start of the variable declaration to declare that variable as a constant. Syntax – const data_type var_name = value;
The type of the constant is the same as the data type of the variables. Following is the list of the types of constants
•The important properties of constant variables in 'C' defined using the const keyword are as follows:
1. Initialization with Declaration Initialize the constant variable at the time of its declaration. Otherwise, it will store the garbage value. 2. Immutability The constant variables in c are immutable after its definition, i.e., they can be initialized only once in the whole program. After that, we cannot modify the value stored inside that variable.