2. Constant
Refer to fixed values.
Values do not change during the execution of a
program.
Uses the secondary storage area.
For every language, constants are same.
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala.
2
4. Numeric constant
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala.
4
Have numeric value having a combination of sequence of digits.
0-9 as alone digits or combination of 0-9 with or without decimal point.
6. Integer numeric constant
Decimal integer
•A set of digits 0-9, preceded by an optional – or + sign.
•Embedded spaces, commas, non-digit characters are not permitted between digits.
•Examples are 123, -321, 0 , 654321, +78
Octal integer
•Consist of any combination of digits 0-7, with a leading 0.
•Examples are 037, 0, 0435, 0551
Hexadecimal
Integer
•Sequence of digits preceded by 0x or 0X.
•Also include alphabets A through F or a through f representing numbers 10-15.
•Examples are 0x2, 0X9F, oxbcd, 0X.
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala.
6
7. Range of integer constants
Generally it is machine dependent for largest integer value.
On 16-bit machines, it is 32767.
On 32-bit machines, it is 2,147,483,647.
Also possible to store larger integer constants by appending qualifiers like U, L and UL.
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala.
7
8. Examples:
Unsigned integer
Unsigned long integer
Long integer
• 56789U
• 56789u
• 985674213UL
• 985674213ul
• 9876543L
• 9876543l
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala.
8
9. Real Constant
Real
constants
Are represented by numbers containing fractional parts like 15.456
Are shown in decimal notation, having a whole number followed by a decimal point and the fractional point.
Possible to omit digits before or after the decimal points e.g. 215. , .95 , -.72 , +.5
May also be expressed in exponential(or scientific) notation. General form is mantissa e exponent
Example is 215.65 may be written as 2.1565e2
e2 means multiply by 102
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala.
9
10. Real Constants
Real
constants
Mantissa is either a real number represented in decimal notation or an integer.
Exponent is an integer number with an optional plus or minus sign.
Letter e separating the mantissa and the exponent can be written inn uppercase or lowercase.
Embedded white space is not allowed.
Are useful for very large or very small numbers e.g. 9500000000 may be written as 9.5E9 or 95E8 and -0.000000348 be
as -3.48E-7
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala.
10
11. Single character constant
Contains a single character enclosed in single quote marks e.g. ‘5’
, ‘X’.
Character constant is not the same as the numbers.
Have integer values known as ASCII values e.g. ‘a’ have 97 as its
ASCII value..
Also possible to perform arithmetic operations on character
constants.
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala.
11
12. String constants
A sequence of characters enclosed in double quotes.
Characters may be letters, numbers, special characters,
and blank spaces e.g. “Hello”, “1987”
Single character string is not equivalent to a character
constant and does not have an equivalent integer value.
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala.
12