C++ Lecture 4 PPT PDF
C++ Lecture 4 PPT PDF
Lecture- 4
Raghav Garg
Control Statements
(continued)
Predict the output Output
1.
#include<iostream>
using namespace std;
int main() {
int x = 10, y = 20 ;
if (x == y) ;
cout << x << ” “ << y ;
return 0;
}
Predict the output Output
3
int main() {
·
int x = 3, y = 5 ; ·
S
if (x == 3) d
Binary banner
~Cool if-else compact
s
Ternary Operator
Ternary
cin marks;
else cont"Fail";
A
Ca
w int main(){ 2
Wchar x; X
a
~int a = 2;
Wx = (a > 0) ? 'a' : 'S';
~cout << "Value of x : " << I
x << endl;
Wcout << "Value of a : "<< a;
return 0;
}
int x;
int y 3, =
if (y > 4)
X = 1;
else
X = 2,
**
Predict the output 11
24
1! 2
=
< 5 =
↓
1!=1
int main(){ ⑯ I -S
↓ L
int x;
X 1
- 30
⑧
I
do this ; case I:
cont"Ok";
case constant 2 :
do this ; case 2:
3 - Wed
y, Thurs
3 - Fri
6 -
Sat
1 esun
Ques : Write a program to input month number and
print total number of days in month using switch
case.
1 s Jane 31 Switch (condition) [
case 1:
2 - Feb 28 do this
March 31 3
3 -
-
30
4 - April
31
3 -
May -
6 - June 30
31
7
-
July -
*
int a, bi
in a bi
charch;
inch;
Predict the output output
102 0
10y
= =
x =
int main() {
~int x = 3, y, z ;
Wy = x = 10 ;
-> O
-z = x < 10 ;
~cout << "x = “ << x << “y = “ << y << ”z = " << z ;
return 0;
}
Output
Predict the output
I %
#include<iostream>
int main( ) {
~int k = 35 ;
return 0;
}
Output
I
Predict the output
#include<iostream>
int main( ) {
vint k = 35 ;
return 0;
}
Predict the output
amaw
to i
I
#include<iostream>
using namespace std;
int main( ) {
int i = 65 ;
char j = 'A' ;
if ( i == j )
cout << "P stands for PhysicsWallah" ;
else
cout<<"P stands for pwskills" ;
return 0;
}
The Real Thing: Output
I
·
This works
if ( 3 + 2 % 5 )
Even this works
cout << "This works" ; endl;
·
if ( a = 10 ) a
surprisingly even
if ( -5 )
endl
cout << "Surprisingly even this works" 46
;
The Real Thing:
if ( condition )
statement ;
if ( expression )
statement ;
THANK YOU
Looks, coppe, PP-1, PP-2
Problems