In C, a variable is a named location in memory that is used to store a value. Each variable has a specific type, such as int, float, char, etc., which determines the size and format of the stored value.
To declare a variable in C, the following syntax is used:
type variable_name;
For example, to declare an integer variable named “age”, the following syntax is used:
int age;
To assign a value to a variable, the following syntax is used:
variable_name = value;
For example:
age = 25;
Alternatively, a variable can be declared and initialized in one statement, like this:
int age = 25;
Variables can be used in expressions and assignments, like this:
int x = 10; int y = 20; int z = x + y;
In this example, the variable “z” is assigned the value of 30, which is the sum of the values of “x” and “y”.
Variables are an essential concept in programming, as they allow programs to store and manipulate data. C supports a wide range of variable types, including integers, floating-point numbers, characters, and arrays, among others.