hamburger

C++ Interview Questions and Answers

By BYJU'S Exam Prep

Updated on: September 25th, 2023

Candidates actively preparing for the GATE CSE Engineering exam 2023 and other CSE Engineering competitive exams can get C++ interview questions and answers here. A basic summary of the types of questions to be expected in the tests may be found in C++ Interview Questions and Answers.

By resolving C++ interview questions and answers that are objectively based, subjects will be more clearly understood. Here are 5 specifically chosen questions that were chosen based on the most recent GATE CSE syllabus

C++ Interview Question 1

The C++ language is ______ object-oriented language.

  1. Pure object-oriented
  2. Not object-oriented
  3. Semi Object-oriented or Partial Object-oriented
  4. None of the above

Answer: C. Semi Object-oriented or Partial Object-oriented

Solution

The Pure Object-Oriented Language has three fundamental properties: inheritance, encapsulation, and Polymorphism. The Pure-Object oriented language is any computer language that supports all three of these properties. In contrast, programming languages that partially or only partially offer these three properties are referred to as partial or semi-object-oriented languages.

The following are the main reasons for the term semi-object oriented language as applied to the C++ programming language:

  • Availability of the Friend function

A class that has been designated as a friend may access the private and protected members of that class. Even while it may be really helpful for a while, it still goes against the rules of object-oriented features.

  • Concept of the Global variable

As everyone knows, the C++ language allows us to declare global variables that are easily accessible from anywhere in the programme. Again, C++ does not completely protect users’ privacy because anyone can access and alter the data and information. As a result, it provides partial encapsulation, in contrast to Java Language, which only permits users to specify variables within classes and provides them access specifiers.

  • The main function is outside the class.

Despite being an object-oriented language, C++ does not inherently (or implicitly) support object-oriented programming. Thus, a user can create valid, well-defined C++ code without touching an object.

C++ Interview Question 2

Which of the following is the correct identifier?    

  1. $var_name
  2. VAR_123
  3. varname@
  4. None of the above

Answer: B. VAR_123

Solution

There are a few guidelines that users must follow while writing Identifiers.

  • Only underscore (_), numbers, and uppercase/lowercase letters are permitted.
  • Only non-digit characters are used as the first character.
  • There shouldn’t be any special characters, such as  @.$ etc.

C++ Interview Question 3

Which of the following statement is true about the new and malloc?

  1. The pointer object initialization of a specific class using malloc also needs to include constructor calls; on the other hand, doing so with the
    ew keyword does not include any constructor calls.
  2. The pointer object initialization of a specific class using the
    ew keyword also needs to include a constructor call. On the other hand, doing so with the malloc does not need to include any constructor calls.
  3. Pointer object initialization of a specific class using either
    ew or malloc involves the constructor call.
  1. Only II
  2. Both II and III
  3. Only I
  4. None of the above

Answer: A. Only II

Solution

When initializing an object for a class, using the
ew keyword also includes calling the constructor, but using the malloc keyword eliminates the need for the constructor call. The word
ew is included explicitly in the C++ language for this reason mainly. On the other hand, the “malloc” function allocates an equal amount of memory to the class size when it is used to assign memory to a specific pointer. The
ew keyword also requires initialization; as a result, it calls the Constructor for that specific class.

C++ Interview Question 4

How are the references different from the pointer?

  1. A reference cannot be modified once it initialized
  2. There is no need of an extra operator for dereferencing a reference
  3. A reference cannot be NULL
  4. All of the above

Answer: D. All of the above

Solution

These are some fundamental explanations for why references and pointers differ greatly from one another.

The * operator is necessary in the case of pointers in order to dereference the value they contain. The reference does not require any kind of operator for deference.

Once initialized, a Reference cannot be changed; however, this is not true of pointers.

A reference cannot become NULL, while a pointer can.

C++ Interview Question 5

Read the following program carefully and find out which concept from the given options is not used or missing in the following program?

Program

class A  

{  

    int x;  

    public:  

    void print(){cout<

}  

   

class B: public A  

{  

    int y;  

public:  

    void assign(int a){y = a;}  

}  

  1. Polymorphism
  2. Encapsulation
  3. Inheritance
  4. Abstraction

Answer: D. Abstraction

Solution

The variables X and Y are both private members in the programme above, which implies they are both hidden from the class’s the outside world. As a result, abstraction is being used in this situation.

The additional data components and their associated functions are kept in a separate class, so the idea of encapsulation is also applied here. Additionally, Class B is derived from Class A, demonstrating the usage of inheritance; however, we could not locate an overloaded function in any of the classes. As a result, the supplied programme either lacks or does not use the idea of polymorphism.

☛ Related Questions:

Our Apps Playstore
POPULAR EXAMS
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 help@byjusexamprep.com
Home Practice Test Series Premium