C++ interview questions and answers focuses on “Statements”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ interview questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.
C++ questions on “Statements” along with answers, explanations and/or solutions:
Q 1. How are many sequences of statements present in c++?
A. 4
B. 5
C. 6
D. 7
Show Answer
Answer:-B. 5Explanation
There are five sequences of statements. They are Preprocessor directives, Comments, Declarations, Function Declarations, Executable statements.Q 2. The if..else statement can be replaced by which operator?
A. Bitwise operator
B. Addition operator
C. Multiplicative operator
D. Conditional operator
Show Answer
Answer:-D. Conditional operatorExplanation
In the conditional operator, it will predicate the output using the given condition.Q 3. The switch statement is also called as?
A. choosing structure
B. selective structure
C. certain structure
D. bitwise structure
Show Answer
Answer:-B. selective structureExplanation
The switch statement is used to choose the certain code to execute, So it is also called as selective structure.Q 4. The destination statement for the goto label is identified by what label?
A. $
B. @
C. *
D. :
Show Answer
Answer:-D. :Explanation
colon is used at the end of labels of goto statements.Q 5. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main ()
{
int n;
for (n = 5; n > 0; n–)
{
cout << n;
if (n == 3)
break;
}
return 0;
}
A. 543
B. 540
C. 5432
D. 539
Show Answer
Answer:-A. 543Explanation
In this program, We are printing the numbers in reverse order but by using break statement we stopped printing on 3. Output: $ g++ stat.cpp $ a.out 543Q 6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int a = 10;
if (a < 15)
{
time:
cout << a;
goto time;
}
break;
return 0;
}
A. 1010
B. 104
C. infinitely print 10
D. compile time error
Show Answer
Answer:-D. compile time errorExplanation
Because the break statement need to be presented inside a loop or a switch statement.Q 7. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int n = 15;
for ( ; 😉
cout << n;
return 0;
}
A. error
B.15
C. infinite times of printing n
D. none of the mentioned
Show Answer
Answer:-C. infinite times of printing nExplanation
There is not a condition in the for loop, So it will loop continuously.Q 8. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int i;
for (i = 0; i < 10; i++);
{
cout << i;
}
return 0;
}
A. 0123456789
B. 10
C. 012345678910
D. compile time error
Show Answer
Answer:-B. 10Explanation
for loop with a semicolon is called as body less for loop. It is used only for incrementing the variable values. So in this program the value is incremented and printed as 10. Output: $ g++ stat2.cpp $ a.out 10Q 9. How many types of loops are there in C++?
A. 4
B. 2
C. 3
D. 1
Show Answer
Answer:-A. 4Explanation
There are four types of loop. They are the while, do while, nested, for the loop.Q 10. Which looping process is best used when the number of iterations is known?
A. while for
B. for
C. do-while
D. all looping processes require that the iterations be known
Leave a Reply