|Access||Adobe photoshop||Algoritmi||Autocad||Baze de date||C||C sharp|
|Calculatoare||Corel draw||Dot net||Excel||Fox pro||Frontpage||Hardware|
|Php||Power point||Retele calculatoare||Sql||Tutorials||Webdesign||Windows|
|Asp||Autocad||C||Dot net||Excel||Fox pro||Html||Java|
The normal integral constants are obvious: things like
L at the end of an
integer constant to force it to be long. To make the constant
unsigned, one of
U can be used to do the job.
Integer constants can be written in hexadecimal by preceding the constant
0X and using the upper
or lower case letters
f in the usual way.
Be careful about octal constants. They are indicated by starting the number
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
that can hold the value.
Plain octal or hexadecimal constants will use this listint unsigned int long unsigned long
If the constant is suffixed by
If it is suffixed by
and finally, if it suffixed by both
L, it can only be an
All that was done to try to give you ‘what you meant’; what it does mean is
that it is hard to work out exactly what the type of a constant expression is
if you don't know something about the hardware. Hopefully, good compilers will
warn when a constant is promoted up to another length and the
L etc. is not specified.
A nasty bug hides here:printf('value of 32768 is %dn', 32768);
On a 16-bit two's complement machine,
long by the rules
given above. But
only expecting an
int as an
indicates that). The type of the argument is just wrong. For the ultimate in
safety-conscious programming, you should cast such cases to the right type:
It might interest you to note that there are no negative constants;
Character constants actually have type
(for historical reasons) and are written by placing a sequence of characters
between single quote marks:
Wide character constants are written just as above, but prefixed with
Regrettably it is
valid to have more than one character in the sequence, giving a
machine-dependent result. Single characters are the best from the portability
point of view, resulting in an ordinary integer constant whose value is the
machine representation of the single character. The introduction of extended
characters may cause you to stumble over this by accident; if
'<a>' is a multibyte character
(encoded with a shift-in shift-out around it) then
'<a>' will be a plain character
constant, but containing several characters, just like the more obvious
'abcde'. This is bound to lead to
trouble in the future; let's hope that compilers will warn about it.
To ease the way of representing some special characters that would otherwise
be hard to get into a character constant (or hard to read; does
Table 2.10. C escape sequences
It is also possible to use numeric escape sequences to specify a character
in terms of the internal value used to represent it. A
sequence of either
ooo is up to three
octal digits and
is any number of hexadecimal digits respectively. A common version of it
by a letter
f, then the safe way to do it is to use
the string joining feature:
only contains one character, with all three of
fs eaten up in the
Some of the escape sequences aren't too obvious, so a brief explanation is
needed. To get a single quote as a character constant you type
?'. The escape
There are two distinct purposes behind the escape sequences. It's obviously necessary to be able to represent characters such as single quote and backslash unambiguously: that is one purpose. The second purpose applies to the following sequences which control the motions of a printing device when they are sent to it, as follows:
Ring the bell if there is one. Do not move.
Go to the first position on the ‘next page’, whatever that may mean for the output device.
Go to the start of the next line.
Go back to the start of the current line.
Go to the next horizontal tab position.
Go to the start of the line at the next vertical tab position.
if there is no such position, the behaviour is unspecified. The Standard
carefully avoids mentioning the physical directions of movement of the output
device which are not necessarily the top to bottom, left to right movements
common in Western cultural environments.
It is guaranteed that each escape sequence has a unique integral value which
can be stored in a
These follow the usual format:1.0
and so on. For readability, even if part of the number is zero, it is a good idea to show it:1.0
The exponent part shows the number of powers of ten that the rest of the number should be raised to, so3.0e3
is equivalent in value to the integer constant3000
As you can see, the
can also be
constants all have type
unless they are suffixed with
F to mean
L to mean long double.
For completeness, here is the formal description of a real constant:
A real constant is one of:
In either case followed by an optional one of
Efollowed by an optional
followed by a digit sequence.
A digit sequence is an arbitrary combination of one or more digits.
Politica de confidentialitate|
Adauga cod HTML in site