Ø Variable: -
A variable is a data
name that may be used to store a data value. A variable may take different
values at different times during program execution. Variable names may consist
of letters, digits and the underscore ( _ ) characters. A variable name can be
chosen by the programmer in a meaningful way so as to reflect its functions or
nature in the program.
Rules for variable naming:-
1.
They must begin with a letter.
2.
ANSI (American National Standard Institute) standard recognizes a length of 31
characters. However, length should not be normally more than 8 characters,
since only the first 8 characters are treated as significant by many compilers.
3.
Upper case and lower case are significant that is, the variable area is not the same as Area or AREA.
4.
It should not be a keyword.
5.
White space is not allowed.
Example:
- Roll No is invalid but Roll_No is valid variable name.
Types of variable: -
There
are 2 types of variables.
·
Numeric
Variable: - The variables which stores the numeric data only
is called numeric variable. It can be whole number or decimal number. Example:
10, 11, 3.14 etc.
·
String
Variables: - The variable which stores the character data
only is called String variable. It can be a single character or string.
Examples: ‘a’, “apple” etc.
Ø Constant:
-
A constant is a value that does not change
during the program execution. There are several types of constants. They are:
a) Integer constant:
- An integer constant refers a sequence of digits.
Examples:
123, 23, 0 etc.
b) Real (Floating constant):
- Floating point constant contains a decimal point. Examples: 3.14, 6.12, etc
c) Character:
- A character constants are enclosed within single quote. Examples: ‘a’, ‘b’
etc.
d) String constant:
- A string constant is a sequence of characters enclosed in double quote. Examples: “Hi this is PLK sir”, “2075” etc.
e) Symbolic constant:
- A symbolic constant is simply an identifier used in place of a constant. In C
symbolic constants are usually defined at the start of program. Examples:
# define pi
3.14
Your suggestions / query encourages more to share things like this. Feel free to comment in below box.
What ever you think about it...