What Are C Variables?
1.A C variable is a named identifier associated with a location in computer memory that stores a value.
2.The value can be changed as the program runs.
For example: int age = 18;
Here, “age” is the variable name and “18” is the value assigned to it. The data type of this variable is “int” which stands for integer.
In C, there are different types of variables (defined with different keywords), for example:
1.int – stores integers (whole numbers), without decimals, such as 123 or -123
2.float – stores floating point numbers, with decimals, such as 19.99 or -19.99
3.char – stores single characters, such as ‘a’ or ‘B’. Char values are surrounded by single quotes
Declaring (Creating) Variables
Syntax
type variableName = value;
Ex.
Int a=20;
OR
Int a;
a=20;
Rules to Declare a Variable in C Language
- Variables must be given an appropriate name.
- Variables must begin with a letter or an underscore (_).
- Variables names cannot contain any special characters, such as #, @, or $.
- Variables names cannot contain spaces.
- Variables names must be unique.
- Variables must be declared before being used.
- Variables must be declared with a specific data type.
- Reserved words (such as int) cannot be used as Variable names