June 4, 2019

Srikaanth

WNS Global C++ Interview Questions Answers

WNS Global Most Frequently Asked C++ Interview Questions Answers

What Is Meant By Const_cast?

The const_cast is used to convert a const to a non-const. This is shown in the following program

#include
void main( )
{
     const int a = 0  ;
     int *ptr = ( int * ) &a ; //one way
     ptr = const_cast_ ( &a ) ; //better way
}
Here, the address of the const variable a is assigned to the pointer to a non-const variable. The const_cast is also used when we want to change the data members of a class inside the const member functions. The following code snippet shows this

class sample
{
    private
    int data;
    public
      void func( ) const
      {
        (const_cast (this))->data = 70 ;
      }
};
WNS Global Most Frequently Asked C++ Interview Questions Answers
WNS Global Most Frequently Asked C++ Interview Questions Answers

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.

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.

What Is Encapsulation In C++?

Packaging an object's variables within its methods is called encapsulation.

What Is A C++ Object?

Object is a software bundle of variables and related methods. Objects have state and behavior.

Describe Private, Protected And Public - The Differences And Give Examples.

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 xdim = 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

bool isPinned = MyPoint.pinned; // no problem.

Stl Containers - What Are The Types Of Stl Containers?

There are 3 types of STL containers

Adaptive containers like queue, stack.
Associative containers like set, map.
Sequence containers like vector, deque.

Rtti - What Is Rtti In C++?

RTTI stands for "Run Time Type Identification". In an inheritance hierarchy, we can find out the exact type of the objet of which it is member. It can be done by using

dynamic id operator.
typecast operator.

Assignment Operator - What Is The Diffrence Between A "assignment Operator" And A "copy Constructor"?

In assignment operator, you are assigning a value to an existing object. But in copy constructor, you are creating a new object and then assigning a value to that object.
For example

complex cl,c2;
cl=c2;           //this is assignment
complex c3=c2;  //copy constructor.

If You Hear The Cpu Fan Is Running And The Monitor Power Is Still On, But You Did Not See Anything Show Up In The Monitor Screen. What Would You Do To Find Out What Is Going Wrong?

I would use the ping command to check whether the machine is still alive(connect to the network) or it is dead.


Can You Be Able To Identify Between Straight- Through And Cross- Over Cable Wiring? And In What Case Do You Use Straight- Through And Cross-over?

Straight-through is type of wiring that is one to connection, Cross- over is type of wiring which those wires are got switched We use Straight-through cable when we connect between NIC Adapter and Hub. Using Cross¬over cable when connect between two NIC Adapters or sometime between two hubs.

What Are The Defining Traits Of An Object-oriented Language?

The defining traits of an object-oriented langauge are

encapsulation,
inheritance,
polymorphism.

What Methods Can Be Overridden In Java?

In C++ terminology, all public methods in Java are virtual. Therefore, all Java methods can be overwritten in subclasses except those that are declared final, static, and private.

https://mytecbooks.blogspot.com/2019/06/wns-global-c-interview-questions-answers.html
Subscribe to get more Posts :