• +91 9723535972
  • info@interviewmaterial.com

CPlusPlus Interview Questions and Answers

CPlusPlus Interview Questions and Answers

Question - 31 : - Describe PRIVATE, PROTECTED and PUBLIC – the differences and give examples.

Answer - 31 : - class Point2D{ int x; int y; public int color; protected bool pinned; public Point2D() : x(0) , y(0) {} //default (no argument) constructor }; Point2D MyPoint; You cannot directly access private data members when they are declared (implicitly) private: MyPoint.x = 5; // Compiler will issue a compile ERROR //Nor yoy can see them: int x_dim = MyPoint.x; // Compiler will issue a compile ERROR On the other hand, you can assign and read the public data members: MyPoint.color = 255; // no problem int col = MyPoint.color; // no problem With protected data members you can read them but not write them: MyPoint.pinned = true; // Compiler will issue a compile ERROR bool isPinned = MyPoint.pinned; // no problem

Question - 32 : - What is namespace?

Answer - 32 : - Namespaces allow us to group a set of global classes, objects and/or functions under a name. To say it somehow, they serve to split the global scope in sub-scopes known as namespaces. The form to use namespaces is: namespace identifier { namespace-body } Where identifier is any valid identifier and namespace-body is the set of classes, objects and functions that are included within the namespace. For example: namespace general { int a, b; } In this case, a and b are normal variables integrated within the general namespace. In order to access to these variables from outside the namespace we have to use the scope operator ::. For example, to access the previous variables we would have to put: general::a general::b The functionality of namespaces is specially useful in case that there is a possibility that a global object or function can have the same name than another one, causing a redefinition error.

Question - 33 : - What is a COPY CONSTRUCTOR and when is it called?

Answer - 33 : - A copy constructor is a method that accepts an object of the same class and copies it’s data members to the object on the left part of assignement: class Point2D{ int x; int y; public int color; protected bool pinned; public Point2D() : x(0) , y(0) {} //default (no argument) constructor public Point2D( const Point2D & ) ; }; Point2D::Point2D( const Point2D & p ) { this->x = p.x; this->y = p.y; this->color = p.color; this->pinned = p.pinned; } main(){ Point2D MyPoint; MyPoint.color = 345; Point2D AnotherPoint = Point2D( MyPoint ); // now AnotherPoint has color = 345

Question - 34 : - What is Boyce Codd Normal form?

Answer - 34 : - A relation schema R is in BCNF with respect to a set F of functional dependencies if for all functional dependencies in F+ of the form a-> , where a and b is a subset of R, at least one of the following holds: * a- > b is a trivial functional dependency (b is a subset of a) * a is a superkey for schema R

Question - 35 : - What is virtual class and friend class?

Answer - 35 : - Friend classes are used when two or more classes are designed to work together and need access to each other's implementation in ways that the rest of the world shouldn't be allowed to have. In other words, they help keep private things private. For instance, it may be desirable for class DatabaseCursor to have more privilege to the internals of class Database than main() has.

Question - 36 : - What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?

Answer - 36 : - virtual

Question - 37 : - What do you mean by binding of data and functions?

Answer - 37 : - Encapsulation.

Question - 38 : - What are 2 ways of exporting a function from a DLL?

Answer - 38 : - 1.Taking a reference to the function from the DLL instance. 2. Using the DLL ’s Type Library

Question - 39 : - What is the difference between an object and a class?

Answer - 39 : - Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects. - A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don't change. - The class to which an object belongs is also (usually) static. If a particular object belongs to a certain class at the time that it is created then it almost certainly will still belong to that class right up until the time that it is destroyed. - An Object on the other hand has a limited lifespan. Objects are created and eventually destroyed. Also during that lifetime, the attributes of the object may undergo significant change. Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321]. quicksort ((data + 222), 100);

Question - 40 : - What is a class?

Answer - 40 : - Class is a user-defined data type in C++. It can be created to solve a particular kind of problem. After creation the user need not know the specifics of the working of a class.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners