Wednesday, 18 December 2013

C++ multiple type Questions and Answers

Question 1. What is the correct value to return to the operating system upon the successful completion of a program?

A. -1

B. 1
C. 0
D. Programs do not return a value.


Question 2. What is the only function all C++ programs must contain?

A. start()

B. system()
C. main()
D. program()


Question 3. What punctuation is used to signal the beginning and end of code blocks?

A. { }

B. -> and <-
C. BEGIN and END
D. ( and )


Question 4. What punctuation ends most lines of C++ code?

A. . (dot)

B. ; (semi-colon)
C. : (colon)
D. ' (single quote)


Question 5. Which of the following is a correct comment?

A. */ Comments */

B. ** Comment **
C. /* Comment */
D. { Comment }


Question 6.Which of the following is not a correct variable type?

A. float

B. real
C. int
D. double


Question 7.Which of the following is the correct operator to compare two variables?

A. :=

B. =
C. equal
D. ==


Question 8. Which of the following is true?

A. 1

B. 66
C. .1
D. -1
E. All of the above


Question 9. Which of the following is the boolean operator for logical-and?

A. &

B. &&
C. |
D. |&


Question 10. Evaluate !(1 && !(0 || 1)).

A. True

B. False
C. Unevaluatable


Question 11: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 12: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 13: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 14: Which of the following is not a looping statement in C?

a.       while
b.      until
c.       do
d.      for

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

a.       break
b.      goto
c.       exit
d.      switch

Question 16:Which of the following is selection statement in C++?

a.       break
b.      goto
c.       exit
d.      switch

Question17: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 18: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 19: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 20: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. 0  2. C. main() 3. A. { }4. B. ;5. C. /* Comment */6. B. real7. D. == 8. E. All of the above  9. B. && 10. A. True 11. c. 12.b.  13.d  14.b  15.d  16.d  17. c   18.a  19.c. 20. c. 

No comments:

Post a Comment