Lecture 2
Lecture 2
CS/CE 224/272
Nadia Nasir
• namespace:
• a collection of names and their definitions. Allows different
namespaces to use the same names without confusion.
main() function
The execution of all C++ programs begins with the main function,
regardless of where the function is actually located within the code.
What is a Variable?
Declaring a variable means specifying both its name and its data type.
C++ Data Types
simple structured
address
float double long double
pointer reference
Datatypes
• Signed integers types:
• short, int, long, and long long
• Unsigned integer types
• unsigned short, unsigned int, unsigned long, unsigned long long
• Decimal datatypes
• float, double
• Boolean data type
• bool
• Character data type
• char
• Nothing data type
• void
Datatypes
Type Typical Bit Width Typical Range
char 1byte -127 to 127 or 0 to 255
• Some are preferred at times over other. You will know which ones to
use as you practise!
• Another variation
• The output will be the same as the for loop we earlier saw
Do-while loop
• Consider that a homework and a reading exercise.