Professional Documents
Culture Documents
C++ Lecture 2 PPT PDF
C++ Lecture 2 PPT PDF
Raghav Garg
Today’s checklist
1) Taking Input
2) Operators
3) Typecasting
4) Hierarchy of operators
5) Char and ASCII
Taking input // Let us take a simple example
int x;
cout<<”Enter a number\n”;
int y = x*x;
I
Enter values 4
of p and &
main(){
v
int p,q;
↑5 p 1q
=
=5
}
Types of Operators
n
=
=
5
Comparison
! = Not Equals to
I
↳ 7
main() (
int X 3;
=
n 7;
=
<<n;
cout
3
C++ Relational Operators
int 7;
+= x
=
n
+
= 8;//x x
=
8;
+
-= 10
n
=
10;1/n
=
x
=
-
/= 2 1 5;/w u/s;
=
=
%=
Ques: What is the result of the following code fragment?
Output
bool p = false;
bool q = false;
V Δ
q
bool r = true;
cout<<(p <=
ID q <=
A r);
↓
q 2
=
=
p
=
=
Left to Right
1 =
=
r
1
char data type
char ch = ‘a’;
↓
ASCII values #' +
35
char ch = ‘a’;
'A' +
65 (a 97
- (0' -
48
(367 ↑
↓
⑱
S
!
S
~
char ch = ‘a’;
z
G..H.
F
pi did end
A
1
↓
26
137
-12
-
-
=
2
int xj
Typecasting
cinsca;
x
=
9.7 - 0.7
[9.7] 9
=
x 0.13
=
-0.13 ⑮
n
=
3 - 0.34
0.7
(x) x
=
-
[n]
y
Hierarchy of operators /> +, -
Output
I
int i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8 ;
cout<<i;
6/1 + 1 +
8 -
2 0
+
=>
1 1
+ +
8 -
2 0
+
2 8
+ -
2 +
0
-
18 -
2 0
+
8 +
0 8
=
23/4 6/4 f
I
=
=
diff.
253/4 2+0
=
0
=
**
Hierarchy of operators
BOMAS
()>%,*,/< +, -
>7,7 ,2,2) =.!
=
=
Ques: What is the result of the following code fragment?
Toupu
I
int main()
{
vint num1;
huma ↳
vint p = 5, q = 10;
~p += q -= p;
cout<<p<<" "<<q<<endl;
return 0;
p p q
=
+
}
18
p5 5
= +
=
q
- =
p ->
q q
=
-
p
=>
q 10
= -
5 5
=
Ques: What is the result of the following code fragment?
int main()
{
⑬ N
int num1; ↑ 9
int p = 5, q = 10;
p += q -= p;
cout<<p<<" "<<q<<endl;
<
return 0;
}
9 q p
= -
p p q
= +
10 15 = -
5
q
= -
p 5 10 15
=
+ =
Try This!
&NT
I
oco2
vk = i / j * j ;
k =
23
+
3 073 0
= =
~l = j / i * i;
+
-a = i / j * j ; l =
3/2 72 1
=
2 2
=
~b = j / i * i;
vcout<<k<<” “<<l<<” ”<<a<<” “<<b;
}
MCQ Time !
MCQ 1
Which of the following is NOT a character constant
(1) ‘Thank You’
(2) ‘Enter values of P, N, R’
(3) ‘23.56E-03’
/
(4) All the above
MCQ am
3 2
float
The expression, a = 7 / 22 * ( 3.14 + 2 ) * 3 / 5 ; evaluates to
(1) 8.28 * *
03/5
01s +0
MCQ 4
In 3
(2) 6
(3) 4 x u
=
(2%8)
+
x =
THANK YOU