C++ MCQ -3

Question 1:

Find out the error in following block of code.

If (x = 100)

    Cout << ΓÇ£x is 100ΓÇ¥;

a.       100 should be enclosed in quotations

b.      There is no semicolon at the end of first line

c.       Equals to operator mistake

d.      Variable x should not be inside quotation

 
Question 2:

Looping in a program means

a.       Jumping to the specified branch of program

b.      Repeat the specified lines of code

c.       Both of above

d.      None of above

 
Question 3:

The difference between while structure and do structure for looping is

a.       In while statement the condition is tested at the end of first iteration

b.      In do structure the condition is tested at the beginning of first iteration

c.       The do structure decides whether to start the loop code or not whereas while statement decides whether to repeat the code or not

d.      In while structure condition is tested before executing statements inside loop whereas in do structure condition is tested before repeating the statements inside loop

 
Question 4:

Which of the following is not a looping statement in C?

a.       while

b.      until

c.       do

d.      for
Question 5:

Which of the following is not a jump statement in C++?

a.       break

b.      goto

c.       exit

d.      switch

 
Question 6:

Which of the following is selection statement in C++?

a.       break

b.      goto

c.       exit

d.      switch

 
Question 7:

The continue statement

a.       resumes the program if it is hanged

b.      resumes the program if it was break was applied

c.       skips the rest of the loop in current iteration

d.      all of above

 
Question 8:

Consider the following two pieces of codes and choose the best answer
Code 1:

switch (x) {

case  1:

cout <<ΓÇ¥x is 1ΓÇ¥;

break;

case 2:

                cout <<ΓÇ¥x is 2ΓÇ¥;

                break;

default:

                cout <<ΓÇ¥value of x unknownΓÇ¥;

}

 
Code 2

If (x==1){

                Cout <<ΓÇ¥x is 1ΓÇ¥;

                }

Else if (x==2){

                Cout << ΓÇ£x is 2ΓÇ¥;

                }

Else{

                Cout <<ΓÇ¥value of x unknownΓÇ¥;

}             

 

a.       Both of the above code fragments have the same behaviour

b.      Both of the above code fragments produce different effects

c.       The first code produces more results than second

d.      The second code produces more results than first.

 
Question 9:

Observe the following block of code and determine what happens when x=2?

switch (x){

case 1:

case 2:

case 3:

                cout<< “x is 3, so jumping to third branch”;

                goto thirdBranch;

default:

                cout<<“x is not within the range, so need to say Thank You!”;

                }

 

a.       Program jumps to the end of switch statement since there is nothing to do for x=2

b.      The code inside default will run since there is no task for x=2, so, default task is run

c.       Will display x is 3, so jumping to third branch and jumps to thirdBranch.

d.      None of above

 
Question 10

Which of the following is false for switch statement in C++?

a.       It uses labels instead of blocks

b.      we need to put break statement at the end of the group of statement of a condition

c.       we can put range for case such as case 1..3

d.      None of above

Answers

 

1.       c. Equals to operator mistake

2.       b. Repeat the specified lines of code

3.       In while structure condition is tested before executing statements inside loop whereas in do structure condition is tested before repeating the statements inside loop

4.       b. Until

5.       d. Switch

6.       d. Switch

7.       c. skips the rest of the loop in current iteration

8.       a. Both of the above code fragments have the same behaviour

9.       c. Will display x is 3, so jumping to third branch and jumps to thirdBranch

10.   c. we can put range for case such as case 1..3

Similar Posts

  • C++ MCQ -7

    Question 1 A variable is/are a.    String that varies during program execution b.    A portion of memory to store a determined value c.    Those numbers that are frequently required in programs d.    None of these   Question 2 Which of the following can not be used as identifiers? a.    Letters b.    Digits c.    Underscores d.   …

  • C++ MCQ-12

    Q.1   The address of a variable temp of type float is          (A) *temp  (B) &temp     (C) float& temp  (D) float temp&     Ans: B   Q.2   What is the output of the following code           char symbol[3]={ΓÇÿaΓÇÖ,ΓÇÿbΓÇÖ,ΓÇÿcΓÇÖ};            for (int index=0; index<3; index++)         cout << symbol…

  • C++ MCQ -9

    Question 1: A function can not be overloaded only by its return type. a. True b. False   Question 2: A function can be overloaded with a different return type if it has all the parameters same. a. True b. False   Question 3: Inline functions involves some additional overhead in running time. a. True…

  • C++ MCQ-10

    Q.16   If we create a file by ΓÇÿifstreamΓÇÖ, then the default mode of the file is _________    (A)  ios :: out  (B)  ios :: in (C)  ios :: app  (D)  ios :: binary     Ans: B   Q.17   A variable defined within a block is visible        (A) from the point of…

  • C++ MCQ-14

    Q.61  An array element is accessed using (A)  a FIFO approach  (B)  an index number (C)  the operator  (D)  a member name     Ans:B   Q.62   If there is a pointer p to object of a base class and it contains the address of an object of a derived class and both classes contain…

  • C++ MCQ-15

    Q.76   Which of the following expressions is illegal? (A)  ( ) 6 10 .  (B)  (false && true) (C)  bool (x) = (bool)10;  (D)  float y = 12.67;       Ans:C   Q.77  The actual source code for implementing a template function is created when   (A) The declaration of function appears. (B) The…

Leave a Reply

Your email address will not be published. Required fields are marked *