Variables in c language
- When we want to store any information(data) on our computer/laptop, we store it in the computer's memory space.
- Instead of remembering the complex address of that memory space where we have stored our data, our operating system provides us with an option to create folders, name them, so that it becomes easier for us to find it and access it.
- Similarly, in C language, when we want to use some data value in our program, we can store it in a memory space and name the memory space so that it becomes easier to access it.
- The naming of an address is known as variable. Variable is the name of memory location. Unlike constant, variables are changeable, we can change value of a variable during execution of a program.
Datatype of Variable
A variable in C language must be given a type, which defines what type of data the variable will hold.
It can be:
char: Can hold/store a character in it.
int: Used to hold an integer.
float: Used to hold a float value.
double: Used to hold a double value.
Rules to name a Variable
- Variable name must not start with a digit.
- Variable name can consist of alphabets, digits and special symbols like underscore
- Blank or spaces are not allowed in variable name.
- Keywords are not allowed as variable name.
- Upper and lower case names are treated as different, as C is case-sensitive, so it is suggested to keep the variable names in lower case.