Integer ConstantsAn integer constant is a sequence of digits, optionally preceded by a plus or minus sign. If the first digit is 0, the integer is taken as an octal constant, in which case all digits that follow must be 0–7. If the first digit is 0 and is immediately followed by the letter x (or X), the integer is taken as a hexadecimal constant, and the digits that follow can be in the range 0–9 or a–f (or A–F). The suffix letter l or L can be added to the end of a decimal integer constant to make it a long int constant. If the value can’t fit into a long int, it’s treated as a long long int. If the suffix letter l or L is added to the end of an octal or a hexadecimal constant, it is taken as a long int if it can fit; if it can’t fit there, it is taken as a long long int. Finally, if it can’t fit in a long long int, it is taken as an unsigned long long int constant. The suffix letters ll or LL can be added to the end of a decimal integer constant to make it a long long int.When added to the end of an octal or a hexadecimal constant, it is taken as a long long int first, and if it can’t fit there, it is taken as an unsigned long long int constant. The suffix u or U can be added to the end of an integer constant to make it unsigned. If the constant is too large to fit inside an unsigned int, it’s taken as an unsigned long int. If it’s too large for an unsigned long int, it’s taken as an unsigned long long int. Both an unsigned and long suffix can be added to an integer constant to make it an unsigned long int. If the constant is too large to fit in an unsigned long int, it’s taken as an unsigned long long int. Both an unsigned and a long-long suffix can be added to an integer constant to make it an unsigned long long int. If an unsuffixed decimal integer constant is too large to fit into a signed int, it is treated as a long int. If it’s too large to fit into a long int, it’s treated as a long long int. If an unsuffixed octal or hexadecimal integer constant is too large to fit into a signed int, it is treated as an unsigned int. If it’s too large to fit into an unsigned int, it’s treated as a long int, and if it’s too large to fit into a long int, it’s treated as an unsigned long int. If it’s too large for an unsigned long int, it’s taken as a long long int. Finally, if it’s too large to fit into a long long int, the constant is treated as an unsigned long long int. Floating-Point ConstantsA floating-point constant consists of a sequence of decimal digits, a decimal point, and another sequence of decimal digits. A minus sign can precede the value to denote a negative value. In addition, either the sequence of digits before the decimal point or after the decimal point can be omitted, but not both. If the floating-point constant is immediately followed by the letter e (or E) and an optionally signed integer, the constant is expressed in scientific notation.This integer (the exponent) represents the power of 10 by which the value preceding the letter e (the mantissa) is multiplied (for example, 1.5e-2 represents 1.5 ×10-2 or .015). A hexadecimal floating constant consists of a leading 0x or 0X, followed by one or more decimal or hexadecimal digits, followed by a p or P, followed by an optionally signed binary exponent. For example, 0x3p10 represents the value 3 × 210. Floating-point constants are treated as double precision values by the compiler.The suffix letter f or F can be added to specify a float constant instead of a double one, and the suffix letter l or L can be added to specify a long double constant. Character ConstantsA character enclosed within single quotation marks is a character constant. How the inclusion of more than one character inside the single quotation marks is handled is implementation-defined.A universal character can be used in a character constant to specify a character not included in the standard character set. Escape SequencesSpecial escape sequences are recognized and are introduced by the backslash character. These escape sequences are listed here: | Character | Meaning |
| | \a | Audible alert | | \b | Backspace | | \f | Form feed | | \n | Newline | | \r | Carriage return | | \t | Horizontal tab | | \v | Vertical tab | | \\ | Backslash | | \” | Double quote | | \’ | Single quote | | \? | Question mark | | \nnn | Octal character value | | \unnnn | Universal character name | | \Unnnnnnnn | Universal character name
| | \xnn | Hexadecimal character value |
In the octal character case, from one to three octal digits can be specified. In the last three cases, hexadecimal digits are used. Wide Character ConstantsA wide character constant is written as L'x'.The type of such a constant is wchar_t, as defined in the standard header file <stddef.h>. Wide character constants provide a way to express a character from a character set that cannot be fully represented with the normal char type. Character String ConstantsA sequence of zero or more characters enclosed within double quotation marks represents a character string constant.Any valid character can be included in the string, including any of the escape characters listed previously.The compiler automatically inserts a null character ('\0') at the end of the string. Normally, the compiler produces a pointer to the first character in the string and the type is “pointer to char.” However, when the string constant is used with the sizeof operator to initialize a character array, or with the & operator, the type of the string constant is “array of char.” Character string constants cannot be modified by the program. Character String ConcatenationThe preprocessor automatically concatenates adjacent character string constants together. The strings can be separated by zero or more whitespace characters. So, the three strings ”a” “ character “ “string” are equivalent to the single string
”a character string” after concatenation.
Multibyte CharactersImplementation-defined sequences of characters can be used to shift between different states in a character string so that multibyte characters can be included. Wide Character String ConstantsCharacter string constants from an extended character set are expressed using the format L'...'.The type of such a constant is “pointer to wchar_t,” where wchar_t is defined in <stddef.h>. Constant Character String ObjectsA constant character string object can be created by placing an @ character in front of a constant character string.The type of the object is NSConstantString. Adjacent constant string objects are concatenated together. So the three string objects @”a” @” character “ @”string” are equivalent to the single string object @”a character string” Enumeration ConstantsAn identifier that has been declared as a value for an enumerated type is taken as a constant of that particular type and is otherwise treated as type int by the compiler. |