C++ MCQs

  1. Which of the following is the correct syntax to output "Hello World" in C++?
    a) echo "Hello World";
    b) Console.WriteLine("Hello World");
    c) cout << "Hello World";
    d) printf("Hello World");
    Answer: c

  2. Which of the following is not a C++ keyword?
    a) public
    b) private
    c) protected
    d) then
    Answer: d

  3. Which of the following is the correct file extension for C++ source files?
    a) .cp
    b) .cpp
    c) .cxx
    d) Both b and c
    Answer: d

  4. What is the default return type of a function in C++ if not specified?
    a) int
    b) void
    c) float
    d) double
    Answer: a

  5. Which of the following is used to comment a single line in C++?
    a) /* comment */
    b) // comment
    c) # comment
    d) -- comment
    Answer: b

  6. Which header file is required for using cout and cin?
    a) <iostream.h>
    b) <stdio.h>
    c) <iostream>
    d) <conio.h>
    Answer: c

  7. Which of the following is not a basic data type in C++?
    a) int
    b) float
    c) bool
    d) real
    Answer: d

  8. Which operator is used for scope resolution in C++?
    a) ::
    b) .
    c) ->
    d) :
    Answer: a

  9. Which of the following is the correct way to declare a constant in C++?
    a) const int x = 10;
    b) int const x = 10;
    c) #define x 10
    d) All of the above
    Answer: d

  10. What does the main() function return in C++ by default?
    a) 1
    b) 0
    c) void
    d) None
    Answer: b


11–20: Control Structures

  1. Which loop is guaranteed to execute at least once?
    a) for
    b) while
    c) do-while
    d) None of the above
    Answer: c

  2. Which statement is used to skip the current iteration in a loop?
    a) exit
    b) break
    c) continue
    d) return
    Answer: c

  3. What is the output of: for(int i=0;i<5;i++){ cout << i; }?
    a) 12345
    b) 01234
    c) 1234
    d) 012345
    Answer: b

  4. Which keyword is used to return a value from a function?
    a) break
    b) goto
    c) return
    d) exit
    Answer: c

  5. Which of the following is used to terminate a switch statement?
    a) return
    b) exit
    c) break
    d) goto
    Answer: c

  6. What is the purpose of the default keyword in a switch case?
    a) It ends the switch block.
    b) It is executed if no other case matches.
    c) It is always executed first.
    d) None of the above
    Answer: b

  7. Which of the following is not a relational operator?
    a) !=
    b) ==
    c) =
    d) >=
    Answer: c

  8. Which of the following loops is entry-controlled?
    a) do-while
    b) while
    c) Both a and b
    d) None
    Answer: b

  9. What is the output of: if (0) cout << "Hi"; else cout << "Bye";?
    a) Hi
    b) Bye
    c) 0
    d) Error
    Answer: b

  10. Which operator is used to check both conditions in an if statement?
    a) &
    b) &&
    c) |
    d) ||
    Answer: b

Post a Comment

0 Comments