Constant
Constants in C refer to fixed values that do not change during the execution of
a program .C supports several types of constants as illustrated
| 1. Constant | |
|
A. Numeric Constant |
|
|
a. Integer Constant |
b. Real Constant |
|
B. Character Constant |
|
|
a. Single Character Constant |
b. String Constant |
Integer Constants
An integer constants refers to a sequence of digits. There are three types of integers, namely, decimal integer ,octal integer and hexadecimal integer.Decimal integer consist of set of digit ,0 through 9,preceded by an optional - or + sign. Valid examples of decimal integer contents are:
Embedded spaces, commas and non-digit characters are not permitted between digits. For example.
are illegal numbers. note that ANSI C supports unary plus which was not defined earlier.
A sequence of digits preceded by 0x or 0X is considered as hexadecimal integer .They may also include alphabets A through F. The letter A through F represent the number s 10 through15.Following are the examples of valid hex integers.
We rarely use octal and hexadecimal numbers in programming.
The largest integer value that can be stored in machine
dependent .It is 32767 on 16-bit machines and 2,147,483,647 on
32-bit machine. It is also possible to store larger integer
constants on these machines by appending qualifiers such as U, L
and UL to the constants. For example:
| 56789U | or 56789u | (unsigned integer) |
| 987612347UL | or 98761234ul | (unsigned long integer) |
| 9876543L | or 98765431l | (long integer) |
Example for this constants
Program
main()
{
printf ("Integer values\n\n");
printf ("%d %d %d\n",32767,32767+1,32767+10);
printf ("\n");
printf ("long integer values\n\n");
printf ("%ld %ld %ld\n",32767L,32767L+1L,32767L+10L);
}
Output
Integer values
32767 -32768 -32759
Long integer values
32767 32768 32777


