- What is C++ primarily used for?
a) Web Development
b) System Programming
c) Mobile App Development
d) Database Management
Answer: b) System Programming - Who developed C++?
a) Dennis Ritchie
b) Bjarne Stroustrup
c) James Gosling
d) Guido van Rossum
Answer: b) Bjarne Stroustrup - Which of the following is a
valid C++ keyword?
a) function
b) int
c) define
d) method
Answer: b) int - What is the correct file
extension for C++ source files?
a) .c
b) .cpp
c) .java
d) .py
Answer: b) .cpp - 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; - 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! - 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 - Which data type is used to
store a single character in C++?
a) string
b) char
c) character
d) text
Answer: b) char - 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 - 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
- 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
- Which function is used to read input from the user in
C++?
a) print()
b) read()
c) cin
d) input()
Answer: c) cin
- 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
- 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
- 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
- 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
- What is the output of true && false in
C++?
a) true
b) false
c) 1
d) 0
Answer: b) false
- 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
- Which function is used to terminate a program in C++?
a) end()
b) return()
c) exit()
d) terminate()
Answer: c) exit()
- 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
- 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 { };
- 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
- 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
- Which operator is used for pointer dereferencing in
C++?
a) &
b) *
c) ->
d) ::
Answer: b) *
- 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