MCQS from C++ Programming Language set 1-25

  1. What is C++ primarily used for?
    a) Web Development
    b) System Programming
    c) Mobile App Development
    d) Database Management
    Answer: b) System Programming
  2. Who developed C++?
    a) Dennis Ritchie
    b) Bjarne Stroustrup
    c) James Gosling
    d) Guido van Rossum
    Answer: b) Bjarne Stroustrup
  3. Which of the following is a valid C++ keyword?
    a) function
    b) int
    c) define
    d) method
    Answer: b) int
  4. What is the correct file extension for C++ source files?
    a) .c
    b) .cpp
    c) .java
    d) .py
    Answer: b) .cpp
  5. Which of the following correctly declares a variable in C++?
    a) int x;
    b) variable x;
    c) x int;
    d) int = x;
    Answer: a) int x;
  6. What is the output of cout << "Hello, World!"; in C++?
    a) Hello, World!
    b) "Hello, World!"
    c) cout << "Hello, World!";
    d) Error
    Answer: a) Hello, World!
  7. Which operator is used to access members of a class in C++?
    a) . (dot)
    b) -> (arrow)
    c) :: (scope resolution)
    d) All of the above
    Answer: d) All of the above
  8. Which data type is used to store a single character in C++?
    a) string
    b) char
    c) character
    d) text
    Answer: b) char
  9. What is the default return type of a function in C++ if not specified?
    a) int
    b) void
    c) float
    d) double
    Answer: a) int
  10. Which of the following is a valid comment in C++?
    a) /* This is a comment */
    b) // This is a comment
    c) # This is a comment
    d) Both a and b
    Answer: d) Both a and b

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

  1. Which function is used to read input from the user in C++?
    a) print()
    b) read()
    c) cin
    d) input()
    Answer: c) cin

  1. What is the output of 5 / 2 in C++ (assuming integer division)?
    a) 2.5
    b) 2
    c) 3
    d) 5/2
    Answer: b) 2

  1. Which header file is required to use the cout and cin objects?
    a) stdio.h
    b) conio.h
    c) iostream
    d) string.h
    Answer: c) iostream

  1. What is the use of the new operator in C++?
    a) Allocates memory dynamically
    b) Declares a new variable
    c) Deletes an existing object
    d) None of the above
    Answer: a) Allocates memory dynamically

  1. What does the sizeof operator return in C++?
    a) The number of bytes of a variable/data type
    b) The address of a variable
    c) The size of the screen
    d) None of the above
    Answer: a) The number of bytes of a variable/data type

  1. What is the output of true && false in C++?
    a) true
    b) false
    c) 1
    d) 0
    Answer: b) false

  1. Which of the following is used to define a constant in C++?
    a) const
    b) final
    c) #define
    d) Both a and c
    Answer: d) Both a and c

  1. Which function is used to terminate a program in C++?
    a) end()
    b) return()
    c) exit()
    d) terminate()
    Answer: c) exit()

  1. What is an object in C++?
    a) A function
    b) An instance of a class
    c) A keyword
    d) None of the above
    Answer: b) An instance of a class

  1. Which of the following is a valid C++ class definition?
    a) 
    class MyClass { };
    b) 
    struct MyClass { };
    c) 
    object MyClass { };
    d) 
    define MyClass { };
    Answer: a) 
    class MyClass { };

  1. What is inheritance in C++?
    a) A function inside a class
    b) Deriving a class from another class
    c) Using pointers in classes
    d) None of the above
    Answer: b) Deriving a class from another class

  1. Which access specifier allows members to be accessible only within the same class?
    a) private
    b) public
    c) protected
    d) None of the above
    Answer: a) private

  1. Which operator is used for pointer dereferencing in C++?
    a) &
    b) *
    c) ->
    d) ::
    Answer: b) *

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

 

Previous Post Next Post

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