A variable is a data name that may be used to store a data value. Unlike constants that remain unchanged during the execution of a program, a variable may take different values at Different times during execution. A variable name can be the programmer in a meaningful way so as to reflect its function or nature in the program.
The rules for writing the variable names are given below.
A variable stores data value of different types and to avoid the
confusion to compiler, variables are declared with a data type.
It can store only the data values of the type associated with
Syntax: data type variable_name=data_value;
Thus,"x" is a variable that can store only integer values.
Constants in C refer to the values that do not change during the execution of the program.Depending on the types of the data they represent,constants are classified in to two classes.
1. Numeric constants: Numeric constants can be classified
a) Integer constants and
b) Real constants.
a) Integer constants: An integer constant refers to a
sequence of digits.These are further classified into three types
depending on the number systems they belong to they are
DECIMAL INTEGER CONSTANT: - A decimal integer constant is
characterized by the following properties.
OCTAL INTEGER CONSTANT:-An octal integer characterized by
the following properties.
A hexa decimal integer constant is characterized by the
Integer numbers are inadequate to represent quantities that vary continuously, such as Distances, heights, etc. These quantities are represented by numbers containing fractional parts Like 17.548. Such numbers are called real constants. The representation of a floating-point .Real constants are often called floating point constant the real constants could be written in two forms, fractional form &exponential form.
RULES WHILE CONSTRUCTING REAL CONSTANTS EXPRESSED IN FRACTIONAL FORM:-
(a) A real constant must have at least one digit.
(b) It must have decimal point.
(c) It could be either +ve or -ve.
(d) Default sign is +ve
(e) No commas (or) blank are allowed with in a real constant
A single character contains a single character constant enclosed
within a pair of a single quote marks.
Example: "a","5" etc
Character constants have integer values that are determined by the computer"s particular character set .most computers make use of the ASCII character set, in which each individual character is numerically encoded.
Example: "A" =65
Maximum of one character is taken within a character constant
A string constant contains sequence of characters (i.e.,
alphabets, digits, special symbols and blank spaces) enclosed in
C supports some special backslash character constants that are
used in output functions. Each character constant has its own
purpose and contains two characters. These character
combinations is called "Escape sequence". Some of them are shown
in the table given below. Constant
"\a", "\b", "\f", "\n", "\r", "\t", "\v", "\"", "\?", "||", "\0"