Professional Documents
Culture Documents
LESSONS
Data Types
C++ has various data types, including:
int: for integer values (e.g., 1, 2, 3, -4, -5)
float: for floating-point values (e.g., 1.23, 4.56, -7.89)
double: for double-precision floating-point values (e.g., 1.23456, 7.8910)
bool: for boolean values (true or false)
char: for single characters (e.g., 'a', 'b', 'c')
In this example, we include the <iostream> library, which provides access to the
input/output functions. We then use cout to display a message on the screen and
cin to get input from the user.
Control Structures
C++ provides various control structures to control the flow of your program,
including:
if-else: allows you to execute different blocks of code depending on a condition
for: allows you to execute a block of code a specified number of times
while: allows you to execute a block of code repeatedly as long as a condition is
true
do-while: allows you to execute a block of code at least once, and then repeatedly
as long as a condition is true
switch: allows you to execute different blocks of code depending on the value of
an expression