FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
in Technical Questions by Goeduhub's Expert (5.8k points)
C and C++ Interview Questions with answers

6 Answers

0 like 0 dislike
by Goeduhub's Expert (5.8k points)
edited by
Best answer

C and C++ Interview Questions Set 2

Q.1. Difference between Class and Structure.

Answer:- Structure: In C language, the structure is used to bundle different type of data types together. The variables inside a structure are called the members of the structure. These members are by default public and can be accessed by using the structure name followed by a dot operator and then the member name.

Class: Class is a successor of the Structure. C++ extends the structure definition to include the functions that operate on its members. By default all the members inside the class are private.

Q.2. What is the difference between an Object and a Class?

Answer:- Class is a blueprint of a project or problem to be solved and consists of variables and methods. These are called the members of the class. We cannot access methods or variables of the class on its own unless they are declared static.

In order to access the class members and put them to use, we should create an instance of a class which is called an Object. The class has an unlimited lifetime whereas an object has a limited lifespan only.

Q.3. What are the various Access Specifiers in C++?

Answer:- C++ supports the following access specifiers:

  • Public: Data members and functions are accessible outside the class.
  • Private: Data members and functions are not accessible outside the class. The exception is the usage of a friend class.
  • Protected: Data members and functions are accessible only to the derived classes

Q.4. When should we use pointers in a C program?


  • To get address of a variable
  • For achieving pass by reference in C: Pointers allow different functions to share and modify their local variables.
  • To pass large structures so that complete copy of the structure can be avoided.
  • To implement “linked” data structures like linked lists and binary trees.

Q.5. What is NULL pointer?

Answer:- NULL is used to indicate that the pointer doesn’t point to a valid location. Ideally, we should initialize pointers as NULL if we don’t know their value at the time of declaration. Also, we should make a pointer NULL when memory pointed by it is deallocated in the middle of a program.

Q.6. What are static functions? What is their use?

Answer:- In C, functions are global by default. The “static” keyword before a function name makes it static. Unlike global functions in C, access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static. Another reason for making functions static can be reuse of the same function name in other files.

Q.7. What is the difference between Method Overloading and Method Overriding in C++?

Answer:- Method overloading is having functions with the same name but different argument list. This is a form of compile-time polymorphism.

Method overriding comes into picture when we rewrite the method that is derived from a base class. Method overriding is used while dealing with run-time polymorphism or virtual functions.

Q.8. What is Inheritance?

Answer:- Inheritance is a process by which we can acquire the characteristics of an existing entity and form a new entity by adding more features to it.

In terms of C++, inheritance is creating a new class by deriving it from an existing class so that this new class has the properties of its parent class as well as its own.

Q.9. What is a friend function?

Answer:- C++ class does not allow its private and protected members to be accessed outside the class. But this rule can be violated by making use of the “Friend” function.As the name itself suggests, friend function is an external function which is a friend of the class. For friend function to access the private and protected methods of the class, we should have a prototype of the friend function with the keyword “friend” included inside the class.

Q.10.  What is an Inline function in C++?

Answer:- Inline function is a function that is compiled by the compiler as the point of calling the function and the code is substituted at that point. This makes compiling faster. This function is defined by prefixing the function prototype with the keyword “inline”.

Q.11. Explain Pass by value and Pass by reference.

Answer:- Pass by value: In this approach we pass copy of actual variables in function as a parameter. Hence any modification on parameters inside the function will not reflect in the actual variable. For example:


int main(){

    int a=5,b=10;


    printf("%d      %d",a,b);

    return 0; } 

void swap(int a,int b){

    int temp;

    temp =a;


    b=temp; }

Output: 5    10

Pass by reference: In this approach we pass memory address actual variables in function as a parameter. Hence any modification on parameters inside the function will reflect in the actual variable. For example:


int main(){

    int a=5,b=10;


    printf("%d %d",a,b);

    return 0; } 

void swap(int *a,int *b){

    int  *temp;

    *temp =*a;


    *b=*temp; }

Output: 10 5

Q.12. What is Static Member?

Answer:- Static is a keyword in C++ used to give special characteristics to an element. Static elements are allocated storage only once in a program lifetime in static storage area. And they have a scope till the program lifetime.

Q.13. Name the Operators that cannot be Overloaded.


  • sizeof – sizeof operator
  • . – Dot operator
  • .* – dereferencing operator
  • -> – member dereferencing operator
  • :: – scope resolution operator
  • ?: – conditional operator

Q.14.  Function can be overloaded based on the parameter which is a value or a reference. Explain if the statement is true.

Answer:- False. Both, Passing by value and Passing by reference look identical to the caller.

Q.15. State the difference between delete and delete[].

Answer:- “delete[]” is used to release the memory allocated to an array which was allocated using new[]. “delete” is used to release one chunk of memory which was allocated using new.

For any queries or doubts refer to comment section mentioning question number  with doubt

For more Technical MCQ's and Interview Questions Click here

0 like 0 dislike
by (592 points)


ypes of access specifiers in C++

  1. public

  2. private

  3. protected

Public Specifier

Public class members and functions can be used from outside of a class by any function or other classes. You can access public data members or function directly by using dot operator (.) or (arrow operator-> with pointers).

Protected Specifier

Protected class members and functions can be used inside its class. Protected members and functions cannot be accessed from other classes directly. Additionally protected access specifier allows friend functions and classes to access these data members and functions. Protected data members and functions can be used by the class derived from this class. More information about access modifiers and inheritance can be found in C++ Inheritance

Private Specifier

Private class members and functions can be used only inside of class and by friend functions and classes.

0 like 0 dislike
by (592 points)


Null Pointer is a pointer that does not point to any memory location. It stores the base address of the segment. The null pointer basically stores the Null value while void is the type of the pointer. A null pointer is a special reserved value which is defined in a stddef header file.

0 like 0 dislike
by (592 points)

27/04/2020                     INLINE FUNCTION IN C++

The inline functions are a C++ enhancement feature to increase the execution time of a program. Functions can be instructed to compiler to make them inline so that compiler can replace those function definition wherever those are being called. Compiler replaces the definition of inline functions at compile time instead of referring function definition at runtime.
NOTE- This is just a suggestion to compiler to make the function inline, if function is big (in term of executable instruction etc) then, compiler can ignore the “inline” request and treat the function as normal function.

0 like 0 dislike
by (592 points)

27/04/2020                   inheritance 

Inheritance is one of the key features of Object-oriented programming in C++. It allows user to create a new class (derived class) from an existing class(base class).

The derived class inherits all the features from the base class and can have additional features of its own.

0 like 0 dislike
by (592 points)

27/04/2020                  Friend function

A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.

A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends.

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs


About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © Social::   |  | 


Free Online Directory