PDF 3
PDF 3
Data Types
Terms
Array Floating-point number
Binary system Hexadecimal system
Boolean values Index
Casting Over ow
Characters Run-time error
Compile-time error Stream manipulator
Data type String
Decimal system Under ow
Summary
• C++ has several built-in data types for storing integers (whole numbers), oating-point
numbers (numbers with a decimal point), characters, and Boolean values (true/false).
• Whole numbers are interpreted as int by default. To represent a long, we have to use
the L suf x (eg 10L).
• Using the auto keyword, we can let the compiler infer the type of a variable based on its
initial value.
• Numbers can be represented using the decimal, binary, and hexadecimal systems.
• If we store a value larger or smaller than a data type’s limits, over owing or under owing
occurs.
• Using the sizeof() function, we can see the number of bytes taken by a data type.
• We can use stream manipulators to format data sent to a stream. The most common
manipulators are setw, xed, setprecision, boolalpha, left, and right.
• Array elements can be accessed using an index. The index of the rst element in an
array is 0.
• When we store a smaller value in a larger data type, the value gets automatically cast
(converted to) the larger type. When storing a large value in a smaller data type, we
have to explicit cast the value.
• C-style casting involves pre xing a variable with the target data type in parentheses. In
C++, we use the static_cast operator.
• C++ casting is safer because conversion problems can be caught at the compile-time.
With C-style casting, we won’t know about conversion issues until the run-time.