Professional Documents
Culture Documents
C++ Data Types
C++ Data Types
• Data Type
• A key capability of a programming language
• Establishes both the type of information that can be stored as well as
operations that can be done on that information
• Strings data
• Store a “string” of characters, like a name
• Type is string – specified in double quotes: “John” or “apple”
• Not built-in, comes from a pre-defined library (distributed with C++)
• It is actually a class (which did not exist in the original C language)
• To use strings, must include the string library: #include <string>
• Three types
• short, int, long
• Usually representing different numerical ranges
• We will be using int primarily
• Ranges are compiler dependent
• Generally: short <= int <= long
• On our system, int can store values between -2147483648 and 2147483647
• (approx. +/- 2 billion)
• Two types
• float and double
• We will be using float primarily
• Ranges are compiler and system dependent - on ours:
• float can store pos and neg values between 1e-38 and 1e38 (approx.)
• float has 6 decimal digits of precision
• double has much greater range and precision
• integer assignment
int i, j, k; // declare 3 integers
i= 10;
j= 0;
k= -23;
10, 0 and -23 are literals
Professor John Carelli Kutztown University Computer Science Department
Floating point Literals
Scientific Notation
• Floating point data • Two parts
float x, y, z; // declare 3 floating point • Mantissa – the decimal number
variables before the “e”
x= 3.14159; // decimal notation • Exponent – the characteristic
y= 3.2e5; // scientific notation (exponent) is the integer after
z= -15e-10; the “e”
Numerical values above are floating
point literals
number= mantissa x 10characteristic