Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Theory questions for MID TERM

Difference between C and C++.

Ans) Written below are some differences between C and C++.

1) C is a structural or procedural programming language but C++ is an object-oriented programming


language.
2) C contains 32 keywords but C++ contains 63 keywords.
3) C programming language has .c file extension. C++ programming language has .cpp file
extension.
4) C language does not support access modifiers. C++ support access modifiers.
5) C does not support namespaces but C++ supports namespaces.

Describe features of Object oriented programing.

Ans) Object oriented programming has four main features. They are:

1) Encapsulation: This feature of OOP allows for data hiding, as the data (attributes) of the object
is hidden from the outside world, and can only be accessed through the methods of the object.
2) Inheritance: This is a feature that allows one class (the child class) to inherit the properties and
methods of another class (the parent class). This promotes code reusability.
3) Polymorphism: This is a feature that allows one interface to be used for a general class of
actions. This means that the exact method that gets called is determined at runtime, not at
compile time.
4) Abstraction: This is a feature that allows complex real world problems to be simplified by
modelling them in a way that captures only the required details.

Definition of Class and Object with example.

Ans) A class is a user defined data type. It is a blueprint for declaring and creating objects.
An object is a class instance that allows programmers to use variables and methods from
I inside the class. Example:

***Describe output of the code.

Ans) A code will be given in the question, you will have to describe that code.
Definition of Constructors and Destructors with example.
Ans) Constructors are special member functions that are automatically called when and object is
. created.
Destructors are special member functions that are automatically called when an object is .
I destroyed. They are used to free up memory. Example:

Access modifiers in C++ with examples.

Ans) In C++, there are three access specifiers:

public - members are accessible from outside the class


private - members cannot be accessed (or viewed) from outside the class
protected - members cannot be accessed from outside the class, however, they can be
accessed in inherited classes.

Function overloading and Constructor overloading.


Ans) When two Functions have the same name but take different arguments then it is called Function
Function overloading.
When two Constructors have the same name but take different arguments then it is called
Constructor overloading.

Function Overloading Constructor Overloading


Advantage of Friend Function.

Ans) A friend function is a function that can access the private and protected members of a class even
though it is not a member of that class. So the advantage of friend function is that it allows the
sharing of private class information by a non-member function.

Copy constructor.

Ans) A Copy constructor is a special member function that creates a new object by copying the data
from another object of the same class.

Inline function.

Ans) An inline function is a function that is expanded in line when it is called.

You might also like