Integer Constants:
The Standard has now invented a new way of working out what type an integer constant is. In the old days, if the constant was too big for an int, it got promoted to a long (without warning). Now, the rule is that a plain decimal constant will be fitted into the first in this list
int long unsigned long
that can hold the value.
Plain octal or hexadecimal constants will use this list
int unsigned int long unsigned long
If the constant is suffixed by u or U:
unsigned int unsigned long
If it is suffixed by l or L:
long unsigned long
String Constants:
String constants are sequences of characters enclosed in double quotes. The same backslash sequences that are used in character constants can be used in string constants.
E.g., "hello there", "a newline: \n", "a string\nwith multiple\nlines".
If a string is long and you want to break it up across several lines of code, you can put a backslash just before a (real) newline and the C compiler will throw away both the backslash and the newline, e.g.,
printf ("A very long help message \n that is more readable if it is broken up over \n \
several lines. \n ");
this string contains one real newline (the \n).
Character Constants:
A character constant is a character enclosed in single quotes, e.g., 'a', '2', '.'. Remember that in C, characters are small integers, so you can use a character constant anywhere you can use an integer constant and vise versa
| Sequence |
Represents |
\a |
audible alarm |
\b |
backspace |
\f |
form feed |
\n |
newline |
\r |
carriage return |
\t |
tab |
\v |
vertical tab |
\\ |
backslash |
\' |
quote |
\" |
double quote |
\? |
question mark |
The enum statement:
ENUM is closely related to the #define preprocessor.
It allows you to define a list of aliases which represent integer numbers. For example if you find yourself coding something like:
#define MON 1
#define TUE 2
#define WED 3
You could use enum as below.
enum week { Mon=1, Tue, Wed, Thu, Fri Sat, Sun} days;
or
enum escapes { BELL = '\a', BACKSPACE = '\b', HTAB = '\t',
RETURN = '\r', NEWLINE = '\n', VTAB = '\v' };
or
enum boolean { FALSE = 0, TRUE };
An advantage of enum over #define is that it has scope This means that the variable (just like any other) is only visable within the block it was declared within.
eg, program:
1. enum sample program