Wednesday 11 February 2015

C++ Programming Questions and Answers (Page 3)

Below are some important C++ interview questions which are asked in most MNC company interviews for beginners or professionals.

21. What are the advantages of inheritance in C++?
It permits code reusability. Reusability saves time in program development. It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional.

22. What do you mean by inline function?
The idea behind inline functions is to insert the code of a called function at the point where the function is called. If done carefully, this can improve the application's performance in exchange for increased compile time and possibly (but not always) an increase in the size of the generated binary executables.

23. What is public, protected, private in C++?
* Public, protected and private are three access specifiers in C++.
* Public data members and member functions are accessible outside the class.
* Protected data members and member functions are only available to derived classes.
* Private data members and member functions can't be accessed outside the class. However there is an exception can be using friend classes.

24. What is the difference between class and structure in C++?
Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. Class: Class is a successor of Structure. By default all the members inside the class are private.

25. What is RTTI in C++?
Runtime type identification (RTTI) lets you find the dynamic type of an object when you have only a pointer or a reference to the base type. RTTI is the official way in standard C++ to discover the type of an object and to convert the type of a pointer or reference (that is, dynamic typing). The need came from practical experience with C++. RTTI replaces many homegrown versions with a solid, consistent approach.

26. What is encapsulation in C++?
Packaging an object's variables within its methods is called encapsulation.

27. What do you mean by inheritance?
Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own.

28. What is a COPY CONSTRUCTOR and when is it called?
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

29. What is Boyce Codd Normal form in C++?
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

30. What is virtual class and friend class?
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.
More Questions & Answers :-

1 comment:

  1. Hi There,

    C++ programming interview questions and answers being contrived to exist for many projects simply so it can be run will be the first to hit the wall, but those projects where the functions to make existing transactions cheaper in real world applications will find the elusive real-world demand.

    I have written some code to calculate the number of rolls of wallpaper to decorate a room.

    A value is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas a rvalue is located on the right side of an assignment statement. Each assignment statement must have a value and an rvalue. The lvalue expression must reference a storable variable in memory. It cannot be a constant.

    I have compiled it and at first it worked OK, using it in my C compiler program (LCC Wedit).
    Subsequently I tried running it by clicking on the executable and it does not run and returns code -1 instead of 0. Even if I return to the compiler program it comes up with the same return code.
    Why is this happening?

    Great effort, I wish I saw it earlier. Would have saved my day :)

    Merci Beaucoup,
    Tom

    ReplyDelete