Professional Documents
Culture Documents
1
char Data Type
The smallest integral data type
2
char Data Type
Used to hold single characters or very small integer values
Usually occupies 1 byte of memory
A numeric code representing the character is stored in memory
3
Character Input
Reading in a character:
char ch;
cin >> ch; // Reads in any non‐blank char
cin.get(ch); // Reads in any char
//Example 1.2.4
4
String Literals
Is comprised of characters
between the " "
5
Must #include <string> to create and use string
objects
The C++
string name; string
Class
Can assign values to string
variables with the name = "George";
assignment operator
6
Reading in a string object
string str;
cin >> str; // Reads in a string
3‐7
bool type
• Two values: true and false
• Manipulate logical
(Boolean) expressions
bool Data
Type true and false
• Logical values
allDone finished
1 0
9
Floating‐Point Data Types
Designed to hold real numbers
• 12.45 ‐3.8
Available in different sizes (number of bytes): float, double, and long double
10
Floating‐Point Data Types
C + + U S E S S C I E N T I F I C N O TAT I O N T O R E P R E S E N T R E A L N U M B E R S ( F L O AT I N G ‐ P O I N T
N O TAT I O N )
11
Maximum number of significant digits (decimal places) for
float values is 6 or 7
Maximum number of significant digits for double is 15
Precision: maximum number of significant digits
◦ Float values are called single precision
◦ Double values are called double precision
Constants
14
Allocating Memory with
Constants and Variables
Named constant: memory location whose content can’t change during
execution
The syntax to declare a named constant is:
In C++, const is a reserved word
15
Also called constant variables
16
Benefits of Named Constants
17
1. BUCKYS C++ PROGRAMMING
TUTORIALS ‐ 4 – VARIABLES
2. BUCKYS C++ PROGRAMMING
TUTORIALS ‐ 5 ‐ CREATING A
BASIC CALCULATOR
Other
References 3. BUCKYS C++ PROGRAMMING
TUTORIALS ‐ 6 ‐ VARIABLES
MEMORY CONCEPTS
4. BUCKYS C++ PROGRAMMING
TUTORIALS ‐ 7 ‐ BASIC
ARITHMETIC
18