Basics Questions with Answers

23 practice questions on Basics (C++) with answers and step-by-step solutions. Try 10 samples below, then practise all 23 free in the AptiNest app.

Sample questions

Question 1Medium

Which of the following is correct aboutthe statements given below?
1. All operators can be overloaded in C++.
2. We can change the basic meaning of an operator in C++.

  1. Only I is true.
  2. Both I and II are false.
  3. Only II is true.
  4. Both I and II are true.

Answer: B. Both I and II are false.

Explanation

C++ supports to operator overloading.
But some operator like:

- :: SRO Scope resolution operator
- . (Member Access or Dot operator)
- ?: (Ternary or Conditional Operator)
- .* (Pointer-to-member Operator)

cannot be overload in Cpp.
Overloading means use that operator at many time in a single program.
Or use of that operator for many variable but without change the basic meaning of an operator

Step-by-step solution

  1. Statement 1 says all operators can be overloaded, but operators such as :: and. cannot be overloaded, so it is false.
  2. Statement 2 says overloading can change the basic meaning of an operator, but overloading gives new meaning for user types and does not change the basic meaning, so it is false.
  3. Both statements are false, which is option B.

Why the other options are wrong

  • A. Statement 1 is false, so 'only I is true' is wrong.
  • C. Statement 2 is false, so 'only II is true' is wrong.
  • D. Both statements are false, so 'both are true' is wrong.

Tip: Scope resolution (::), member access (.), ternary (?:) and .* cannot be overloaded.

Question 2Medium

C++ provides facility to specify that the compiler should match function calls with the correct definition at the run time.
This process is called as...?

  1. Static binding
  2. Dynamic Binding
  3. Both a & b
  4. None of above

Answer: B. Dynamic Binding

Explanation

Dynamic Binding is a concept in which association is done at run time.
At the execution of the code C++ provides facility to specify that the compiler match function calls
With the correct definition at the run time is the basic policy of the Dynamic Binding.

Step-by-step solution

  1. Dynamic binding matches function calls with definitions at runtime.
  2. This allows for flexibility in choosing the correct function version.
  3. The process described matches the definition of dynamic binding.

Why the other options are wrong

  • A. Static binding occurs during compile time, not runtime.
  • C. Both options are incorrect; only one is right.
  • D. The correct answer is provided in the options.

Tip: Remember: Dynamic binding happens at runtime, not compile time.

Question 3Medium

Which of the following is not a type of inheritance?

  1. Multiple
  2. Multilevel
  3. Distributive
  4. Hierarchical

Answer: C. Distributive

Explanation

"Inheritance is the mechanism to create new class from the old class".
The types of inheritance is Single, Multilevel ,Multiple, Hierarchical and Hybrid. Distributive is not a type of Inheritance.

Step-by-step solution

  1. C++ inheritance types are single, multiple, multilevel, hierarchical and hybrid.
  2. Multiple (option A), multilevel (option B) and hierarchical (option D) are all real types.
  3. Distributive is not a type of inheritance.
  4. So the answer is Distributive.

Why the other options are wrong

  • A. Multiple inheritance is a real type.
  • B. Multilevel inheritance is a real type.
  • D. Hierarchical inheritance is a real type.

Tip: Only the usual five types count: single, multiple, multilevel, hierarchical, hybrid.

Question 4Medium

Which operator is used to define a member of a class from outside the class definition itself...?

  1. ::
  2. :
  3. >>
  4. <<

Answer: A. ::

Explanation

Scope resolution operator(::) is used to define a function outside a class or when we want to use a global variable but also has a local variable with same name.

Step-by-step solution

  1. The question asks for the operator that defines a class member outside the class.
  2. The form ClassName::member uses the scope resolution operator, written as two colons.
  3. So the answer is option A, ::.

Why the other options are wrong

  • B. A single colon is not the scope resolution operator.
  • C. >> is the extraction operator, used for input.
  • D. << is the insertion operator, used for output.

Tip: Read :: as 'belongs to': Class::member.

Question 5Medium

Which of the following is a mechanism of static polymorphism...?

  1. Operator overloading
  2. Function overloading
  3. Templates
  4. All of the above

Answer: D. All of the above

Explanation

Static polymorphism is a compile time polymorphism. The code is checked at compile time Operator overloading, Function Overloading, Templates are the derived types of the polymorphism.

Step-by-step solution

  1. Static polymorphism is resolved at compile time.
  2. Operator overloading, function overloading and templates are all resolved at compile time.
  3. So all of the above are static polymorphism mechanisms, which is option D.

Why the other options are wrong

  • A. Operator overloading is also a static polymorphism mechanism, so it alone is not the full answer.
  • B. Function overloading is also static, so it alone is not the full answer.
  • C. Templates are also static, so they alone are not the full answer.

Tip: Compile-time polymorphism covers overloading and templates; run-time polymorphism uses virtual functions.

Question 6Medium

Which of the following correctly describes the meaning "namespace" feature in C++...?

  1. Namespaces refer to the memory space allocated for names used in a program
  2. Namespaces refer to space between the names in a program
  3. Namespaces provide facilities for organizing the names in aprogram to avoid name
  4. Namespaces provide facilities for organizing the names in aprogram to avoid name clashes.

Answer: D. Namespaces provide facilities for organizing the names in aprogram to avoid name clashes.

Explanation

The names may be use many time in the program so avoid the name clashes new concept is launched in cpp named namespace.
The syntax of using is syntax:

using namespace std;

hear You can also avoid prepending of namespaces with the using namespace directive.
This directive tells the compiler that the subsequent code is making use of names in the specified namespace.
The namespace is thus implied for the following code:

Step-by-step solution

  1. Namespaces organize names to avoid clashes.
  2. They prevent naming conflicts between different parts of a program.
  3. Option D correctly describes this feature.

Why the other options are wrong

  • A. Memory space is not what namespaces refer to.
  • B. Space between names doesn't make sense in programming context.

Tip: Use namespaces to keep your code clean and avoid naming issues.

Question 7Medium

Which of the following provides a reuse mechanism...?

  1. Abstraction
  2. Inheritance
  3. Dynamic binding
  4. Encapsulation

Answer: B. Inheritance

Explanation

One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application.
This also provides an opportunity to reuse the code functionality and fast implementation time.
When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class.
This existing class is called the base class, and the new class is referred to as the derived class.

Step-by-step solution

  1. Inheritance allows a class to reuse code from another class.
  2. The derived class inherits properties and methods of the base class.
  3. This enables code reuse without rewriting existing functionality.
  4. Thus, inheritance provides a reuse mechanism.
  5. Final answer: B (Inheritance).

Why the other options are wrong

  • A. Abstraction hides implementation details, not for reuse.
  • C. Dynamic binding resolves method calls at runtime, not for reuse.
  • D. Encapsulation bundles data and methods, but doesn't directly enable reuse.

Tip: Remember inheritance is key for reusing code in OOP.

Question 8Medium

Which of the following languages is a subset of C++ language...?

  1. C language
  2. Java Language
  3. C# language
  4. B language

Answer: A. C language

Explanation

C++ was built on C and adds classes and other features, so C is the language that C++ extends and contains. Java and C# are separate languages, and B is an older language that led to C.

Step-by-step solution

  1. C++ was designed as an extension of C, so C is the language whose features are all part of C++.
  2. Java and C# are separate languages with their own syntax and runtime.
  3. B is an older language and is not part of C++.
  4. So the correct answer is option A, C language.

Why the other options are wrong

  • B. Java is a separate language, not a subset of C++
  • C. C# is a separate language with its own design, not a subset of C++
  • D. B is an older language and is not part of C++

Tip: C++ extends C; Java and C# are separate languages.

Question 9Medium

The conditional compilation

  1. It is taken care of by the compiler
  2. It is setting the compiler option conditionally
  3. It is compiling a program based on a condition
  4. none of above

Answer: C. It is compiling a program based on a condition

Explanation

Compiler is use to check the written code of the language.
Conditional compiler is to set the compilation process depends on the condition.

Step-by-step solution

  1. Conditional compilation means the compiler includes or skips parts of the code based on a condition.
  2. Preprocessor directives such as #if and #ifdef decide which code is compiled.
  3. So the correct meaning is compiling a program based on a condition, which is option C.

Why the other options are wrong

  • A. The compiler does not decide conditions by itself; the programmer writes the condition.
  • B. Conditional compilation does not set compiler options.
  • D. Option C is correct, so 'none of above' is wrong.

Tip: Conditional compilation uses #if, #ifdef and #endif to choose which code is compiled.

Question 10Medium

In C++ every statement end with?

  1. Colon (:)
  2. Comma (,)
  3. Dot (.)
  4. None of the above

Answer: D. None of the above

Explanation

Every C++ statement end with semicolon (;).

Step-by-step solution

  1. In C++ each statement is ended by a semicolon.
  2. The options are colon, comma and dot, and none of these ends a statement.
  3. So none of the above is correct.

Why the other options are wrong

  • A. A colon ends a label, not a statement.
  • B. A comma separates items in a list, not statements.
  • C. A dot is used for member access, not to end a statement.

Tip: Statements end with a semicolon, so look for that first.

Practise all 23 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all C++ topics · All topics