Variables :-
A variable is a name given to a storage area that holds a particular value. In C programming each variable specify the types which specify the size of that variable(like int, float, char ...etc.) and by using these variables u can perform various operations.
Variables in c programming |
Here are few examples of variables -
int var;
- Here var is a variable of type int which can store an integer value.
float _myVar = 2.00;
- _myVar is a variables of type float which stores a floating points values(i.e decimal values).
char c;
- Here cis a variable of type character which can store an character value.
Rules of naming variables :-
- Variables names should only contain only letters (Uppercase and Lowercase)and numbers and a special character underscore(_).
- The first letter of the variable name should start with a letter or an underscore (you cannot start with a number).
- variables cannot contain any special characters other then numbers, letters and underscore.
- Variables in C programming iscase sensitive i.e Uppercase and lowercase characters are treated differently.
Few Examples of valid variables:-
int _var12;
char _character;
float n1_num;
Few Examples of invalid variables:-
int 1var1;
-This is invalid because the first character here is a number.
char ch$;
-This is invalid because the last character here is dollar symbol which cannot be used.
float _n1#
-Again this would generate an error as we cannot use ampersand.
Assigning value to a variable:-
Variable in c |
The variable act like a bucket to hold or to store values of particular data types like int, float ...etc.
We can assign values to a variable by using an assignment operator, when we use an assignment operator it will assign the value on the left side of it to the variable.
For example:-
- int var = 99;
- flpat a = 99.99; This statement will assign 99.99 which is an floating pont value to the variable a.
0 Comments