Sunday, January 13, 2013

C++ Interview questions and answers,part -02

C++ Interview questions and answers,part -02
When do you use bool data type?

The bool data type can take only two values true or false

What is function overloading in C++?

You can have multiple functions with same name using function overloading facility of C++. You
can use same name for multiple functions when all these functions are doing same thing. 

What is operator overloading in C++?

With this facility in C++, you can give additional meaning to operators.

Define Inline Function.

When the function is defined Inline, the C++ compiler puts the function body inside the calling function. You can define function as Inline when the function body is small and need to be called many times, thus reduces the overhead in calling a function like passing values, passing control, returning values, returning control.  

Define class using C++.

A class holds the data and functions that operate on the data. It serves as the template of an
object. 

Explain constructors and destructors.

Constructors are the member functions of the class that executes automatically whenever an
object is created. Constructors have the same name as the class. Constructors initialize the
class. Constructors can’t have return type. Destructors are called when the objects are destroyed

Destructors are usually used to deallocate memory and do other cleanup for a class object and its class members when the object is destroyed. A destructor is called for a class object when that object passes out of scope or is explicitly deleted. A destructor takes no arguments and has no return type.

When do you use this pointer?

'this pointer' is used as a pointer to the class object instance by the member function. The
address of the class instance is passed as an implicit parameter to the member functions

What is new and delete operator?

In C++, when you want dynamic memory, you can use operator new. It returns a pointer to the beginning of the new block of memory allocated. It returns a pointer to the beginning of the new block of memory allocated. 

When memory allocated by new operator is no longer required, it is freed using operator delete. 
Explain the difference between structures and classes.

Syntactically and functionally, both structures and classes are identical. By default, members of structures have public accessibility and public inheritance from their parent(s), while members of classes are private and inherit privately from their parent(s)

Define local class in C++.

Local class is define within the scope of a function and nested within a function. E.g.
int func1()
{
              class localclass1
              {
              };
}

Explain container class and its types in C++.

A container stores many entities and provide sequential or direct access to them. List, vector and strings are such containers in standard template library. The string class is a container that holds chars. All container classes access the contained elements safely and efficiently by using iterators. Container class is a class that hold group of same or mixed objects in memory. It can be heterogeneous and homogeneous. Heterogeneous container class can hold mixed objects in memory whereas when it is holding same objects, it is called as homogeneous container class.   

Define an Iterator class.

A container class hold group of objects and iterator class is used to traverse through the objects maintained by a container class. The iterator class provides access to the classes inside a container. They are objects that point to other objects. Iterator points to one element in a range, and then it is possible to increment it so that it points to the next element

There are several different types of iterators:
input_iterator output_iterator forward_iterator bidirectional_iterator random_iterator reverse_iterator

Define storage classes in C++.

Storage class defined for a variable determines the accessibility and longevity of the variable. The accessibility of the variable relates to the portion of the program that has access to the variable. The longevity of the variable refers to the length of time the variable exists within the program. 

Auto
Automatic variable, also called as local variable and it has scope only within the function block
where it is defined.

External
 External variable are defined outside any function and memory is set aside for this type of variable once it is declared and remained until the end of the program. These variables are also called global variables

Static 
The static automatic variables, as with local variables, are accessible only within the function in which it is defined. Static automatic variables exist until the program ends in the same manner as external variables. In order to maintain value between function calls, the static variable takes its presence

Define namespace in C++.

Namespaces groups together entities like classes, objects and functions under a name.  Namespaces provide a way to avoid name collisions of variables, types, classes or functions. Namespaces reduces the use of nested class thus reduces the inconvenience of handling nested class.    

Define access privileges in C++.

You have access privileges in C++ such as public, protected and private that helps in
encapsulation of data at various level.    

Private
If data are declared as private in a class then it is accessible by the member functions of the class where they are declared. The private member functions can be accessed only by the members of the class. By default, any member of the class is considered as private by the C++ compiler, if no specifier is declared for the member.       
 
Public
The member functions with public access specifier can be accessed outside of the class. This
kind of members is accessed by creating instance of the class

Protected
Protected members are accessible by the class itself and it's sub-classes. The members with protected specifier act exactly like private as long as they are referenced within the class or from the instance of the class. This specifier specially used when you need to use inheritance facility of C++. The protected members become private of a child class in case of private inheritance, public in case of public inheritance, and stay protected in case of protected inheritance.  

What is the default access level?

The access privileges in C++ are private, public and protected. The default access level assigned to members of a class is private. Private members of a class are accessible only within the class and by friends of the class. Protected members are accessible by the class itself and its sub- classes. Public members of a class can be accessed by anyone.

Explain friend class in C++.

When a class declares another class as its friend, it is giving complete access to all its data and methods including private and protected data and methods to the friend class member methodsFriendship is one way only, which means if A declares B as its friend it does NOT mean that A can access private data of B. It only means that B can access all data of A.

Please Share it! :)

Ditulis Oleh : Nangraj Hari: 4:41 AM Kategori:

0 comments:

Post a Comment

 
PLEASE VISIT MY OTHER BLOG TO DOWNLOAD LATEST FULL CRACKED SOFTWARES,GAMES,COMPUTER NOTES,VIDEO TUTORIALS,AND MUCH MORECLICK HERE