Identifiers:
All the words that
we'll use in our C programs will be either keywords or identifiers.
Keywords are defined and can't be changed by
the user, while identifiers are user defined words and are used to names to
entities like variables, arrays, functions, structures etc.
Rules for naming
identifiers are:
- The name should
consist of only alphabets (both upper and lower case), digits and
underscore sign( _ ).
- First character
should be an alphabet or underscore.
- The name should
not be a keyword.
- Since C is case
sensitive, the uppercase and lowercase letters are considered different.
- An identifier name may be arbitrarily long.
Variables:
Variable is a name that can be -used to store values. Variables can take different values but one at a time. These values can be changed during execution of the program. A data type is associated with each variable. The data type of the variable decides what values it can take.
The rules for naming variables are same as that for naming identifiers.
It is must to declare a variable before it is used in the program. Declaration of a variable specifies it’s name and datatype. The type and range of values that a variable can store depends upon its datatype.
The syntax of declaration of a variable is-
datatype variablename;
Here datatype may be int, float, char, double etc. Some examples of declaration of variables are
int
x;
float
salary;
char
grade;
Here x is a variable of type int, salary is a variable of type float, and grade is a variable of type char.
We
can also declare more than one variable in a single declaration. For example- )
int
x, y., z, total;
Here
x, y, z, total are all variables of type int.
Initialization of Variables:
When a variable is declared it contains undefined value commonly known as garbage value. If we want we can assign some initial value to the variable during the declaration itself, this is called initialization of the variable.
For
example
int
a = 5;
float
x = 8.9, Y = 10.5;
char
ch = 'y';
double
num = 0.15197e-7;
int l, m, n, total = 0;
Datatypes:
No comments:
Post a Comment