Introduction to C++ Programming
Introduction to C++ Programming
First 2022/2023
Computation
Compiling,
cout << "Welcome to C++!" << endl; Source Code
return 0;
}
Linker
Result
Sample Run:
My first C++ program.
Hello World
// Hello World program comment
a:
// changing the value of a variable
int a = 7; // a variable of type int called a 7
20
a += 2; // increment a's value by 2
21
++a; // increment a's value (by 1)
Output
• The syntax of cout and << is:
36
Form and Style
int
int main()
main() {{
int
int integer1,
integer1, integer2,
integer2, sum;
sum;
cout
cout <<
<< "Enter
"Enter first
first integer\n";
integer\n";
cin
cin >>
>> integer1;
integer1;
cout
cout <<
<< "Enter
"Enter second
second integer\n";
integer\n";
cin
cin >>
>> integer2;
integer2;
sum
sum == integer1
integer1 ++ integer2;
integer2;
cout
cout <<
<< "Sum
"Sum is
is "" <<
<< sum
sum <<
<< endl;
endl;
return
return 0;
0;
}}
Types and literals
• Built-in types
– Boolean type • Boolean literals
• bool – true false
– Character types • Character literals
• char – 'a', 'x', '4', '\n', '$'
– Integer types • Integer literals
• Int – 0, 1, 123, -6, 245, -698
04/19/2025 49
Precedence Evaluation
What is the value of the expression at the bottom of the
screen?
42
32
0 32
0 4
3 30 8
( 1 + 2 ) % 3 * 4 + 5 * 6 / 7 * ( 8 % 9 ) + 10
Type Conversion (Casting)
y = w + x; //Line 4: error
Another Program
#include <iostream.h>
Using namespace std;
int main() {
double fahr,celcius;
return 0;
}
Math Operator Quiz
04/19/2025 56
cin and the Extraction Operator >>
• Expression is evaluated
• Value is printed
• Manipulator is used to format the output
– Example: cout<< endl;