Course Content
Programming in C
About Lesson

An integer constant like 123 is an int. A long constant ends with the letter L (or l) like 123456789L; an integer constant too big to fit into an int will also be taken as a long. Unsigned constants are suffixed with a U (or u) and the suffix UL (or ul) indicates unsigned long.

Floating-point constants contain a decimal point (3.14) or an exponent (1e-4) or both; their type is double, unless suffixed. The suffix F (or f) indicates a float constant; L (or l) indicates a long double.

The value of an integer can be specified in octal or hexadecimal instead of decimal number system. A leading zero (0) on an integer constant means octal; a leading 0x or 0X means hexadecimal. For example, decimal number 24 can be written as 030 in octal and 0x18 (or 0X18) in hexadecimal. Octal and hexadecimal constants may also be followed by L (or l) to make them long and U (or u) to make them unsigned.

A character constant is one character written within single quotes, such as ‘x’. The value of a character constant is the numeric value of the character in the machine’s character set. For example, in the ASCII character set, the constant ‘0’ has the value 48.

Certain characters can be represented in character and string constants by escape sequences. Here is a complete list of escape sequences.

\aalert (bell) character\\backslash
\bbackspace\?question mark
\fformfeed\'single quote
\nnewline\"double quote
\rcarriage return\ooooctal number
\thorizontal tab\xhhhexadecimal number
\vvertical tab

Examples:

#define VTAB '13'    /* ASCII for vertical tab is 013 in octal */
#define VTAB 'xb'    /* ASCII for vertical tab is b in hexadecimal */

A constant expression involves only constants and may be evaluated during compilation rather than run-time, and may be used at any place a constant can occur.

#define NUM 10

int arr[NUM * 2];

A string constant or string literal is a sequence of zero or more characters surrounded by double quotes. For example: “Hello World”.
String constants can be concatenated at compile time:

"Hello" " World"

is equivalent to

"Hello World"

This is useful for splitting long strings across several lines.
Technically, a string is an array of characters with a null character (‘\0’) at the end, so the physical storage required is one more than the number of characters between the quotes.
Remember, ‘x’ is not same as “x”. ‘x’ is a single character, whereas “x” is string (a null terminated array of characters).

We also have enumeration constant, which is a list of constant integer values. For example:

enum boolean { FALSE, TRUE };

The first value in an enum has value 0, the next 1 and so on, unless explicitly specified.
Names in different enumerations must be distinct. Values need not be distinct in the same enumeration.

Scroll to Top