Constant and Variable In C
Constant:
This is a value with one or more decimal digits, either positive or negative the decimal point is optional all these value does not change. This value stored in a memory as constant value which can not be altered.
For ex. 11,2.16,-12,-3.12 etc.
C Constant can be divided into two major categories:
1) Primary Constant.
2) Secondary Constant.
1) Primary Constant:
a)Integer Constant:
Integer Constant is nothing but the numeric constant without having decimal point and it could be either positive or negative.
Ex: 1456, 52,-652,-3
b)Real Constant:
Real Constant are often called floating point constant. The real constant are numeric constant written in two form, fractional and exponential form.It could be either positive or negative.
Ex: 14.5, 1.34, -12.654, 4.1e8
c)Character Constant:
A Character constant is either a single alphabet, a single digit or a single special symbol enclose within single inverted commas. Maximum length of character constant is one character.
Ex: 'A', '2', 'd'
2)Secondary Constant:
a)Array:
An array is a collection of similar element, stored in contiguous memory location.
Ex: a[5].
b)Pointer:
A Pointer must be define so as to point to particular data type.
Ex: int*n, float*rate.
c)Union:
Union is a syntactically identical to structure. An element of union is accessed in the same as the member of structure. A union provides a way to look at the same memory location's in more than one way.
d)Enum:
An Enumerated data type is the which has user specified value.
Ex: the declaration
enum city{Aurangabad,Pune,Nagpur};
To define a variable of type enum city, write enum city name;
Variable:
The value that may change during the program execution is called a variable. This value are store in a memory location as variable which can be accessed by a variable name. Variable name is a just symbolic representation of a memory location.
Ex: int math mark=96
Here, the math mark is a variable of integer type. The variable is assigned value:96.
Rules for constructing Variable Name:
1)A variable name is any combination of alphabet, digit or underscore. There is no length of variable name.
2)The first character in the variable name must be an alphabet or underscore.
3)No commas or blanks are allowed within a variable name.
4)Reserved key word (32 keywords) are not permitted for variable name.
5)No special symbol other than an underscore can be used in variable name.
Comments
Post a Comment