1. How many times will the following code print?
int i;
for(i = 1; i <= 5; i++)
{
cout << “Hello”;
}
(A) 4
(B) 5
(C) 6
(D) Infinite
2. How many times will the following code print?
int i = 0;
while(i < 3)
{
cout << “Hi”;
i++;
}
(A) 2
(B) 4
(C) 3
(D) Infinite
3. How many times will the following code print?
for(int i = 0; i < 10; i += 2)
{
cout << “A”;
}
(A) 8
(B) 10
(C) 5
(D) Infinite
4. How many times will the following code print?
int i = 5;
while(i–)
{
cout << “X”;
}
(A) 5
(B) 4
(C) 6
(D) Infinite
5. How many times will the following code print?
for(int i = 1; i <= 10; i++)
{
if(i % 2 == 0)
cout << “Even”;
}
(A) 4
(B) 6
(C) 5
(D) 10
6. How many times will the following code print?
int i = 0;
do
{
cout << “Hello”;
i++;
}
while(i < 1);
(A) 0
(B) Infinite
(C) 2
(D) 1
7. How many times will the following code print?
for(int i = 10; i > 0; i–)
{
cout << “C++”;
}
(A) 9
(B) 10
(C) 11
(D) Infinite
8. How many times will the following code print?
int i = 1;
while(i <= 5)
{
cout << i;
i += 2;
}
(A) 2
(B) 4
(C) 3
(D) 5
9. How many times will the following code print?
for(int i = 0; i < 5; )
{
cout << “Loop”;
i++;
}
(A) 5
(B) 4
(C) 6
(D) Infinite
10. How many times will the following code print?
int i = 3;
do
{
cout << “Test”;
i–;
}
while(i > 0);
(A) 2
(B) 3
(C) 4
(D) Infinite
1000+ Programming C Plus Plus MCQs
Highly Recommended C++ Important MCQs with Explanation
- Which symbol is used to create multiple inheritances?
- If a derived class object is created, which constructor is called first?
- Which of the following is not a type of constructor?
- a ____ is a member function that is automatically called when a class object is __.
- What is the output of the following code in C++?
- How many times will the following code print?
- Which of the following is a procedural language?
- Which of the following is not a programming language?
- Which of the following is not an example of high-level language?
- While declaring pointer variables which operator do we use?
- To which does the function pointer point to?
- Which of these best describes an array?
- Which of the following is a Python Tuple?
Other important MCQs
Data Structure
Which of the following is not the type of queue?
Database
If one attribute is a determinant of the second, which in turn is a determinant of the third, then the relation cannot be
Python
Which of the following is a Python Tuple?