Variable in C programming
What is variable?
Variable is an entity which can change during the program execution.
OR
Variable is the name of the memory place, where data is stored.
OR
Variable is just like a cup of tea.
How to create a variable
int x;
float y;
char z;
General Syntax
datatype variable_name;
As shown in the above snippet, To create a variable two things are needed...
- Data type
- Variable name
Rules for creating variable name
- Variable name can contains Alphabets(A-Z / a-z), Digits (0-9), and Underscore (_).
- Variable name must begins with an Alphabet or Underscore
- Spaces and Special symbols are not allowed.
- Keywords / Reserved words are not allowed as a variable name.
- Variable name should be meaningful.
- C is a case sensitive programming language, so age, Age, AGE all are different variables.
Some valid / invalid variable names are listed below...
Variable name | Valid / Invalid |
---|---|
name | valid |
father_name | valid |
father's name | invalid |
father's_name | invalid |
avg. | invalid |
2persons | invalid |
person1 | valid |
int | invalid |
integer | valid |
intnum | valid |
FLOAT | valid (Not good practise) |
___AX | valid |
Previous | Back to C Programming index | Next |
Comments