What is a Variable??
In Programming, Variable is the name given to memory location to store some value.
Rules to follow while giving name to a variable (Naming Conventions)
->Variable name should start with a character or underscore( A-Z or a-z or _ ) followed by characters ( A-Z or a-z ) or digits (0-9) or underscores( _ ).
->There should not be any spaces in a variable name
Ex: Std Name (Wrong)
Std_Name(Correct)
-> Variable name Should not be a keyword. For more about Keywords
->In C, uppercase and lowercase letters are distinct (Case Sensitive).
Ex: variable Num is different from num ,NUM.
How To declare a Variable??
It is necessary to declare a variable to intimate the compiler that one variable of type is used in the program.
Syntax for Declaring a Variable:
For declaring a variable we must specify the datatype followed by list of variables of that type.
datatype var_name1,var_name2........var_nameN;
Ex: int num,id;
Initializing a Variable:
Providing the initial values to variables at the time of declaration is known as initializing of a variable.
datatype variable_name=value;
Ex: int num=50;
The values accepted by the variable to store are based on its datatype
0 comments:
Post a Comment