What will be the output of the following code?
int x = 12, y=12;
cout << (x <= y) << endl;
C++ Operators
Quiz
•
Professional Development
•
Professional Development
•
Hard
Zohaib Hasan
Used 292+ times
FREE Resource
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
What will be the output of the following code?
int x = 12, y=12;
cout << (x <= y) << endl;
0
1
true
false
Answer explanation
<= means "less than or equal to", it will be true if any one is satisfied
2.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
What will be the output of the following code?
int x = 2;
cout << x++ << endl;
2
3
Compilation Error
Compiler dependent output
Answer explanation
x++ means "use and then increment"
so x is used (supplied to cout) before incrementing
3.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
What will be the output of the following code?
int x = 2;
cout << --x << endl;
1
2
Compilation Error
Compiler dependent output
Answer explanation
--x means first decrement and then use.
so x is decremented first and then given to cout
4.
MULTIPLE CHOICE QUESTION
45 sec • 5 pts
What will be the output of the following code?
int x = 4+5*7-6%2/2;
cout << x;
39
0
38
40
Answer explanation
*, % and / have higher precedence than + and -
4+5*7-6%2/2
=4+35-0/2
=4+35-0
=39
5.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
What will be the output of the following code?
cout << (5<7 && 7>3) << endl;
0
1
true
false
Answer explanation
In logical operator && (AND), both the sides of operator should result in true to get true.
true in c++ is printed as 1.
6.
MULTIPLE CHOICE QUESTION
45 sec • 5 pts
What will be the output of the following code?
int x=5, y=6, z=7;
cout << (x>y && ++y) << endl;
cout << y << endl;
0
6
1
7
1
6
0
7
Answer explanation
int x=5, y=6, z=7;
x>y && ++y
since x>y is false and for && it is the sufficient condition to get result, other side of the && will not be evaluated.
This (x>y && ++y) expression will give 0 (false).
The value of y will remain 6.
7.
MULTIPLE CHOICE QUESTION
45 sec • 5 pts
What will be the output of the following code?
int x=5, y=6, z=7;
cout << (x<y || ++y) << endl;
cout << y << endl;
0
6
1
7
1
6
0
7
Answer explanation
int x=5, y=6, z=7;
x<y || ++y
since x<y is true and for || it is the sufficient condition to get result, other side of the || will not be evaluated.
This (x<y || ++y) expression will give 1 (true).
The value of y will remain 6.
15 questions
Công nghệ Java_Test1
Quiz
•
Professional Development
20 questions
VCE TalentNext-2021 Quiz-2
Quiz
•
Professional Development
20 questions
MATLAB basics
Quiz
•
Professional Development
20 questions
Python Code
Quiz
•
8th Grade - Professio...
20 questions
CPR_Quiz_Arrays and strings
Quiz
•
Professional Development
15 questions
CPR_Quiz_Chapter4_function
Quiz
•
Professional Development
18 questions
Тесть по PHP #1
Quiz
•
Professional Development
20 questions
Basics of Python Programming Unit-1
Quiz
•
University - Professi...
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade