C++ Crash Course: a fast-Paced Introduction



Yüklə 7 Mb.
Pdf görüntüsü
səhifə65/71
tarix20.09.2023
ölçüsü7 Mb.
#145939
1   ...   61   62   63   64   65   66   67   68   ...   71
C Crash Course A Fast-Paced Introduction by Josh Lospinoso

W A R N I N G
The octal prefix is a holdover from the B language, back in the days of the PDP-8 
computer and ubiquitous octal literals. C, and by extension C++, continues the dub-
ious tradition. You must be careful, for example, when you’re hardcoding ZIP codes:
int mit_zip_code = 02139; // Won't compile
Eliminate leading zeros on decimal literals; otherwise, they’ll cease to be decimal. 
This line doesn’t compile because 9 is not an octal digit.
By default, an integer literal’s type is one of the following: 
int

long
, or 
long long
. An integer literal’s type is the smallest of these three types that 
fits. (This is defined by the language and will be enforced by the compiler.)
If you want more control, you can supply suffixes to an integer literal to 
specify its type (suffixes are case insensitive, so you can choose the style you 
like best): 
• 
The 
unsigned
suffix 
u
or 
U
• 
The 
long
suffix 
l
or 
L
• 
The 
long long
suffix 
ll
or 
LL
You can combine the 
unsigned
suffix with either the 
long
or the 
long
long
suffix to specify signed-ness and size. Table 2-2 shows the possible types 
that a suffix combination can take. Allowed types are shown with a check 
mark (

). For binary, octal, and hexadecimal literals, you can omit the 
u
or 
U
suffix. These are depicted with an asterisk (*). 
Table 2-2: 
Integer Suffixes
Type
(none)
l
/
L
ll
/
LL
u
/
U
ul
/
UL
ull
/
ULL
int

long


long long



unsigned int
*

unsigned long
*
*


unsigned long long
*
*
*





Types
35
The smallest allowed type that still fits the integer literal is the resulting 
type. This means that among all types allowed for a particular integer, the 
smallest type will apply. For example, the integer literal 
112114
could be an 
int
, a 
long
, or a 
long long
. Since an 
int
can store 112114, the resulting integer 
literal is an 
int
. If you really want, say, a 
long
, you can instead specify 
112114L
(or 
112114l
).

Yüklə 7 Mb.

Dostları ilə paylaş:
1   ...   61   62   63   64   65   66   67   68   ...   71




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin