MCQS from C++ Programming Language set 51-75

  1. Which operator is used to define a reference variable in C++?
    a) *
    b) &
    c) ->
    d) %
    Answer: b) &

  1. Which function is used to allocate an array dynamically in C++?
    a) malloc()
    b) new[]
    c) calloc()
    d) allocate()
    Answer: b) new[]

  1. What happens if a pointer is deleted twice in C++?
    a) Compilation error
    b) Runtime error (undefined behavior)
    c) Pointer is reset to NULL
    d) No effect
    Answer: b) Runtime error (undefined behavior)

  1. Which keyword is used to define an abstract class in C++?
    a) abstract
    b) virtual
    c) pure
    d) None of the above
    Answer: b) virtual

  1. Which C++ function is used to copy a string?
    a) strcpy()
    b) strcat()
    c) copy()
    d) strcopy()
    Answer: a) strcpy()

  1. Which of the following is an example of an implicit type conversion in C++?
    a) Type casting using (int)
    b) Conversion done by the compiler
    c) Using static_cast<>
    d) Using dynamic_cast<>
    Answer: b) Conversion done by the compiler

  1. Which of the following is used to handle exceptions in C++?
    a) try, catch, throw
    b) error(), catch()
    c) try(), throw(), finally()
    d) exception(), handle()
    Answer: a) try, catch, throw

  1. Which keyword is used to return control to the calling function in C++?
    a) break
    b) continue
    c) return
    d) goto
    Answer: c) return

  1. Which STL container follows Last-In-First-Out (LIFO) order?
    a) queue
    b) deque
    c) stack
    d) vector
    Answer: c) stack

  1. What does std::endl do in C++?
    a) Moves to the next line
    b) Ends the program
    c) Clears the screen
    d) Terminates the execution
    Answer: a) Moves to the next line

  1. Which of the following is NOT a fundamental C++ data type?
    a) int
    b) double
    c) boolean
    d) float
    Answer: c) boolean

  1. Which feature of C++ allows a class to have multiple functions with the same name but different parameters?
    a) Function overriding
    b) Function overloading
    c) Operator overloading
    d) Encapsulation
    Answer: b) Function overloading

  1. Which operator is used to define scope in C++?
    a) ::
    b) .
    c) ->
    d) :
    Answer: a) ::

  1. Which header file is required to use the vector container in C++?
    a) vector.h
    b) vectors
    c) stdio.h
    d) vector
    Answer: d) vector

  1. Which of the following is NOT a valid C++ control structure?
    a) for
    b) while
    c) loop
    d) do-while
    Answer: c) loop

  1. Which function is automatically called when an object is destroyed in C++?
    a) Constructor
    b) Destructor
    c) Finalizer
    d) Cleanup
    Answer: b) Destructor

  1. Which of the following is an invalid variable name in C++?
    a) my_variable
    b) _myVariable
    c) 2ndVariable
    d) myVariable2
    Answer: c) 2ndVariable

  1. Which of the following statements about inline functions in C++ is true?
    a) They improve performance by reducing function call overhead
    b) They are always compiled as inline
    c) They can only be used for constructors
    d) They must be declared outside a class
    Answer: a) They improve performance by reducing function call overhead

  1. Which C++ function is used to get the length of a string object?
    a) size()
    b) length()
    c) strlen()
    d) Both a and b
    Answer: d) Both a and b

  1. Which of the following statements is true about multiple inheritance in C++?
    a) A class can inherit from only one class
    b) A class can inherit from multiple classes
    c) Multiple inheritance is not supported in C++
    d) Multiple inheritance is allowed but cannot have member functions
    Answer: b) A class can inherit from multiple classes

  1. Which operator is used to check if two values are equal in C++?
    a) =
    b) ==
    c) :=
    d) !=
    Answer: b) ==

  1. Which of the following is NOT a property of an object-oriented programming language?
    a) Encapsulation
    b) Abstraction
    c) Compilation
    d) Polymorphism
    Answer: c) Compilation

  1. Which of the following correctly initializes a reference in C++?
    a) int x = 10; int &y = x;
    b) int x = 10; int *y = x;
    c) int x = 10; int y = &x;
    d) int x = 10; int y = *x;
    Answer: a) int x = 10; int &y = x;

  1. Which function is used to open a file in C++?
    a) fopen()
    b) open()
    c) file()
    d) openfile()
    Answer: b) open()

  1. What is the purpose of the this pointer in C++?
    a) It refers to the calling object
    b) It creates a new object
    c) It destroys the current object
    d) It is used for inheritance
    Answer: a) It refers to the calling object


Previous Post Next Post

نموذج الاتصال