Professional Documents
Culture Documents
Outline
1.
2.
Data Types
3.
4.
Expressions
5.
6.
string type
7.
Input
8.
9.
Output
10.
Processor Directives
11.
C++ Program
Editor
Preprocessor (#)
Library
Compiler
Linker
Loader
Execution (Running)
Syntax Error
/*
Mathematical symbols
Punctuation marks
=<
==
=!
=>
Tokens
Cant be defined.
Illegal Identifier
Description
Employee Salary
!Hello
Is not allowed!
One+two
+ Is not allowed
2nd
2. Data Types
C++ Data Types
Integral
Simple
Structured
Floating-Point
Enumeration
float
double
long double
Pointers
2. Data Types
Data Type
Values
int
to 2147483647 2147483648-
bool
()char
to 127 128-
2 + 5 = 10
20 34 = -14
{
cout << 2 + 5 = << 2 + 5 << endl;
cout << 20 34 = << 20 - 34 << endl;
cout << 2 * 10 = << 2 * 10 << endl;
cout << 8 / 3 = << 8 / 3 << endl;
cout << 11 % 3 = << 11 % 3 << endl;
return 0;
}
2 * 10 = 20
8/3=2
11 % 3 = 2
{
cout << 5.0 + 3.5 = << 5.0 + 3.5 << endl;
cout << 4.2 * 2.5 = << 4.2 * 2.5 << endl;
cout << 5.0 / 2.0 = << 5.0 / 2.0 << endl;
return 0;
{
Initial expression
Equivalent expression
*)Evaluate(
6 + (2 + (6 21)) =
6+ (2 + 15) =
-)Evaluate(
=6 + 17
+)Evaluate first(
23 =
+)Evaluate(
4. Expressions
Integer expressions:
2+3*5
Floating-point expressions:
Mixed expressions:
2 + 3.5 (= 5.5)
6 / 4 + 3.9 (= 4.9)
The cast operator, also called type conversion or type casting takes the
following form: static_cast<dataTypeName>(expression)
Expression
Evaluates to
static_cast<int>(7.9)
static_cast<double>(25)
25.0
static_cast<double>(5+3)
8.0
static_cast<double>(15)/2
15.0/2 = 7.5
static_cast<double>(15/2)
7.0
6. string Type
7. Input
7. Input
7. Input: walk-through
Statement
Explanation
?
num1
?
num2
?
num3
num1 = 18;
18
num1
?
num2
?
num3
45
num1
?
num2
?
num3
num1 + 27 = 18 + 27 = 45
45 will be assigned to num1.
num2 = num1;
45
num1
45
num2
?
num3
num3 = num2 / 5;
45
num1
45
num2
9
num3
num2 / 5 = 45 / 5 = 9. This
value is assigned to num3.
num3 = num3 / 4
45
num1
45
num2
2
num3
num3 / 4 = 9 / 4 = 2. This
value is assigned to num3.
#include<iostream>
using namespace std;
int main()
{
int feet, inches;
cout << "Enter two integers separated by spaces: ";
cin >> feet >> inches;
cout << endl;
cout << "Feet = " << feet << endl;
cout << "Inches = " <<inches << endl;
return 0;
Output:
}
Enter two integers separated by spaces: 23 7
Feet = 23
Inches 7
Increment:
Pre-increment: ++var;
Post-increment: var++;
Decrement:
Pre-decrement: --var;
Post-decrement: var--;
C++ Expressions
x = 5;
y = ++x;
// x = 5 and y = 6
x = 5;
y = x++;
// x = 6 and y = 5
a = 5;
b = 2 + (++a);
// a = 6 and b = 8
a = 5;
b = 2 + (a++);
// a = 6 and b = 7
9. Output
9. Output: Examples
Statement
cout << 29 / 4 << endl;
cout << Hello there. << endl;
Output
7
Hello there.
Hello
there
4+7
A
4 + 7 = 11
Symbol
Escape Sequence
Description
\n
Newline
\t
Tab
\b
Backspace
\r
Return
\\
Backslash
Backslash is printed
Single Quotation
Double Quotation
Preprocessor
directives
are
commands
supplied
to
the