Statements(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option A. -> forNone.
Explanation:-
Answer: Option A. -> 4There are four types of loop. They are while, do while, nested, for loop.
Question 3.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int i;
6.
for (i = 0; i < 10; i++);
7.
{
8.
cout
- 0123456789
- 10
- 012345678910
- compile time error
Explanation:-
Answer: Option B. -> 10for 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
10
Question 4.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int n = 15;
6.
for ( ; ;)
7.
cout
- error
- 15
- infinite times of printing n
- none of the mentioned
Explanation:-
Answer: Option C. -> infinite times of printing nThere is not a condition in the for loop, So it will loop continuously.
Question 5.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int a = 10;
6.
if (a < 15)
7.
{
8.
time:
9.
cout
- 1010
- 10
- infinitely print 10
- compile time error
Explanation:-
Answer: Option D. -> compile time errorBecause the break statement need to be presented inside a loop or a switch statement.
Explanation:-
Answer: Option D. -> :None.
Explanation:-
Answer: Option B. -> selective structureThe switch statement is used to choose the certain code to execute, So it is also called as
selective structure.
Question 8.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main ()
4.
{
5.
int n;
6.
for (n = 5; n > 0; n--)
7.
{
8.
cout
- 543
- 54
- 5432
- 53
Explanation:-
Answer: Option A. -> 543Inthis 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
543
Explanation:-
Answer: Option B. -> Conditional operatorIn the conditional operator,it will predicate the output using the given condition.
Explanation:-
Answer: Option C. -> 5There are five sequence of statements. They are Preprocessor directives,Comments,Declarations,
Function Declarations,Executable statements.