Friday, October 16, 2009

Constants

Constants are elements whose values in the program do not change. In C, there are several different types of
constants.
Integer Constants :
Integer constants are decimal numbers. You can suffix an integer constant with u or U to specify that the constant is
of the unsigned data type. An integer constant suffixed with l or L is a long int constant.
An integer constant is prefixed with a 0 (zero) to indicate that the constant is in the octal format. If an integer constant
is prefixed with 0X or 0x, the constant is a hexadecimal number.
Character Constants :
A character constant is a character enclosed by single quotes. For instance, `C' is a character constant.
In C, there are several character constants that represent certain special characters. (See Table 24.2.)
Table 24.2. Special characters in C.
Floating-Point Constants :
Floating-point constants are decimal numbers that can be suffixed with f, F, l, or L to specify
float or long double. A floating-point constant without a suffix is of the double data type by default. For instance, the
following statements declare and initialize a float variable (flt_num) and a double variable (db_num):
float flt_num = 1234.56f;
double db_num = 1234.56;
A floating-point can also be represented in scientific notation.
String Constants :
A string constant is a sequence of characters enclosed by double quotes. For instance, "This is a string constant." is a
string constant. Note that the double quotes are not part of the content of the string. Also, the C compiler
automatically adds a null character (\0) at the end of a string constant to indicate the end of the string.

No comments:

Post a Comment