Tolal:235 Click:
1
2 3 4 5 6 7 8 9 10 11 12
C++ Interview Questions And Answers
Page 1
Ques: 1 Question :
what is the difference between parameter and argument?
Ans:
Diff b/w parameter and argument is :
Argument bassically is one of the following -
> An Expression in the comma-separated list in a function call.
> A sequence of one or more preprocessor tokens in the comma-separated list in a macro call.
> Its represent the value which you pass to a procedure parameter when you call the procedure. The calling code supplies the arguments when it calls the procedure.
> It is something passed into a function(value), whereas a parameter is the type of data plus the name.
Parameter bassically is one of the following -
> An object that is declared in a function declaration or definition.
> An identifier b/w the parentheses immediately following the macro name in a macro definition.
> It is represent a value that the procedure expects you to pass when you call it. The procedure's declaration defines its parameters.
This example explains the difference b/w a parameter and an argument:
void function(int x, char * rs); //x and rs are parameters
template <class Tem> class M {}; //Tem is a parameter
int main()
{
char c;
char *p = &c;
func(5, p); //5 and p are arguments
M<long> a; //'long' is an argument
M<char> another_a; //'char' is an argument
return 0;
}
Ques: 2
What is the difference between class and structure?
Ans:
Diff b/w Class and Structure is :
Class is difined as-
>Class is a successor of Structure. By default all the members inside the class are private.
>Class is the advanced and the secured form of structure.
>Classes are refernce typed.
>Class can be inherited.
>In Class we can initilase the variable during the declaration.
>Class can not be declared without a tag at the first time.
>Class support polymorphism.
Structure difine as :
> In C++ extended the structure to contain functions also. All declarations inside a structure are by default public.
> Structures contains only data while class bind both data and member functions.
> Structure dosen't support the polymorphism, inheritance and initilization.
> Structure is a collection of the different data type.
> Structure is ovrloaded.
> Structures are value type.
> Structure can be declared without a tag at the first time
Ques: 3 What is the difference between an object and a class?
Ans:
Class and Objects are diff but related concepts. Every objects belogs to the class and evry class have a one or more related objets.
Class are:
> A Class is static.
> A class combination of data(called data members)and functions(called member functions).
> Class is a userdefined datatype with data members and member functions.
> Classe defines object.
> One class can define any no of Object.
> Class is a template(type) or blue print its state how objects should be and behave.
Object are:
> Object is an instance of a class while a class can have many objects.
> Object is a dynamic.
> Objects are the basic runtime entities in an object oriented sysyem.
> Data and function which combine into a single entity is called object.
> Objects are instances of classes which identifies the class propeties.
> Object can't define classes.
> Object can created and destroyed as your necessity.
> Object is defined as a s/w construct which binds data and logic or methods(functions) both.
Ques: 4 Difference between realloc() and free()?
Ans:
Diff b/w realloc() and free():
realloc():
> It is used to free the memory in the program.
> This function is used to resize memory.
> realloc() means it giving string variables into the existed memory
free():
> Basically It is a macro. Macro used to deallocate memory.
> free() function is used free the memory which is allocated by malloc(),calloc() functions.
> free() means it empties the array.
Ques: 5 What is a template?
Ans:
Templates is defined as :
> It is a framework for web pages and sites.
> Its type of model or standard for making comparisons.
> It is a feature of the C++ programming language its allow functions and classes to be operate with generic types.
> It is a tool for enforcing a standard layout and look and feel across multiple pages or within content regions.
> Its a model or pattern used for making multiple copies of a single object.
Ques: 6 What is virtual constructors/destructors?
Ans:
virtual constructors/destructors : Virtual destructors It is a Bassically same as vertual fuction, Its commonly used with inheritance. Since an abstract class must contain a pure virtual method that has to be overridden, a lot of developers commonly declare their destructors pure virtual, since a destructor is sure to be implemented in every subclass.
Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error. There is no virtual constructor coz virtual thing is in run time n constructor is compile time thing.
Ques: 7 What is the difference between operator new and the new operator?
Ans:
Many diff are there :
Operator new is bassically just like malloc and new is the conventinally new in C++. The "New" operator allocates a new instance of an object
from the heap, Its utilising the most appropriate constructor for the arguments passed. This is Like many operators in C++, The "New" operator for a
particular class can be overriden, Although there is rarely a need to do so. "Operator new" is the mechanism for overriding the default heap allocation logic.
Ans:
Operator new() use for the Operator overloading but New Operator for memory allocation.
Ques: 8 Difference between "C structure" and "C++ structure".
Ans:
Many diff are there :
>Structure in C defines as limited to within the module and cannot be initialized outside but Structure in C++ can initialize the objects anywhere within the boundaries of the project.
> C++ have a many methods((Procedures) but in C no methods are there.
> By default C structure are Public and C++ structure are private .
> C does not support Methods inside structure but C++ does.
> In C++ structure we can add functions but in C
structure we can't.
> In C++, structure behaves like class like can add function, and can use properties on class as inheritance, virtual,etc, But in C, structure we can have only data member but not functions.
> Structures in c++ doesnot provide datahiding but a class provides.
> classes support polymorphism, But Structures don't.
Ques: 9 What is the difference between "overloading" and "overriding"?
Ans:
Many Diffreces are there-
Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.
overridding is runtime polymorphism while overloading is compile time polymorphism.
Ques: 10 Difference between a "assignment operator" and a "copy constructor"
Ans:
many diff are there :
> Assignment operator assign the object of one object to another aftr the 1st object is fully created but in copy constructor it
assign the value of one object to another at the time of its creation .
> The copy constructor is use for initialising a new instance from an old instance, And is called when passing variables by value into functions
or as return values out of functions. but in Assignment operator is used to change an existing instance to have the same values as the rvalue, which means that the instance has to be destroyed and re-initialized if it has internal dynamic memory.
> Copy constructor copies a existing object to a non existing object, which we are going to create. Assignment operation can happen between two existing objects.
> The copy constructor is creating a new object. But in The assignment operator has to deal with the existing data in the object.
> Copy constructor creates shallow copy but in assignment operator creates deep copy.
> The copy constructor is called at initialising the object but the assignment operator is used to assign one object to another.
> Copy constructor donot return anything. But in
Assignment operator returns object of same type.
> The copy constructor initializes uninitialized memory, But in assigenment operator starts with an existing initialized objects.
> Copy constuctor initialize the object with the another object of same class But assignment operator can be called on objects of different classes .
Ques: 11 What is the advantage of function overloading according to users point of view?
Ans:
We know that function name is same. But each time we are writing code for each function. In this case it is advantageous than normal function.
Ans:
waste site
Ques: 12 What is difference between visual c++ & ANSI c++ ?
Ans:
Visual C++ is probably the most popular favored compiler, because of it's history of quality and stablity.But in ANSI C++ is a less popular, but is a much more powerful and robust compiler. The IDE is also a lot more powerful than MSVC.
Ques: 13
What is the difference between far pointer and near pointer?
Ans:
Many diff are there :
> A normal pointer can only point to the main memory location, But the far pointer can have an address of any location of ur memory even seconday one also.
> A far pointer is used to access a location which is outside current segment.
> Near pointers are fully recognised and evaluated for their entire width. But in Far pointers only allow normal operations to be done to their offset amount and not the segment or paragraph amount.
Ques: 14
What are virtual functions?
Ans:
virtual functionsdefines as :
> C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. The whole function body can be replaced with a new set of implementation in the derived class.
> A virtual function is a member function which we may redefine for other derived classes, And can ensure that the compiler will call the redefined virtual function for an object of the corresponding derived class, Even if we call that function with a pointer or reference to a base class of the object.
> A virtual function is a member function of a class, which functionality can be over-ridden in its derived classes. It is one that is declared as virtual in the base class using the virtual keyword.
> C++ virtual function properties are:
* A member function of a class.
* Declared with virtual keyword.
* Usually has a different functionality in the derived class.
* A function call is resolved at run-time.
Ques: 15
What is RTTI?
Ans:
RTTI bassicaly Run Time Type Information. It Certain language features to work a limited amount of information about types is required at runtime. This is the Run Time Type Information or RTTI.
Ques: 16
What happens to the member function in the class when copy constructor is invoked?
Ans:
First of all we want to tell you that only the member function have the athourity to invoke any other member function.But cunstructor have a diff property, is that it used to initialise the values to data members. and they are constant and it cannot be invoked any other constuctor. If they are copied compiler should not understand or didnot diffrentiate that what is member function and what is constructor, so ambiquity will be raised.
Ques: 17 What is the difference between block structured language and highly block structured language
Ans:
Block Structure Langguage Bassically a normal programming language in which sections of source code contained within pairs of matching delimiters such as "" and "" (e.g. in C) or "begin" and "end" (e.g. Algol) are executed as a single unit. Its A class of high-level languages in which a program is made up of blocks � which may include nested blocks as components, such nesting being repeated to any depth.
Ques: 18 How will you detect if there is memory leak in your C++ program?
Ans:
Some time before we have got a some problem of detecting memory leaks in our code, and we didn't afforrd the rates of a brittle software package to do that. It's fairly simple to redefine malloc() and free() to your own functions, to track the file and line number of memory leaks. But what about the new() and delete() operators? It's a little more difficult with C++, if we want to figure out the exact line number of a resource leak.
If we are using new and delete operator, We can overload both the operators and can count number off heap allocation and deallocation. You can also get the __FILE__ and __LINE__ to get to know the file name and line number. Now the new and delete of a memory location should be in pair and if its not there is a memroy leak. By using line and file utility you can reach upto the exact location.
Ques: 19
What was the most difficult debug you have ever done?
Ans:
whenever any application get hanged, & we don't know even from wherewe should start debuging....this can be the most difficult .
Ques: 20 What is the use of new operator?
Ans:
In C++ New Operator used to allocate the memory for the object on HEAP. It allocates the memory of size equal to the object of size, The new operator will return NULL or throw an exception on failure.
It provides dynamic storage allocation. Its syntax for an allocation expression containing the new operator is:
>>-+----+--new--+---------------------+--+-(--type--)-+--------->
'-::-' '-(--argument_list--)-' '-new_type---'
>--+-------------------------+---------------------------------><
'-(--+---------------+--)-'
'-initial_value-'
Goto Page:
1
2 3 4 5 6 7 8 9 10 11 12
CPP Objective
CPP Objective Questions And Answers
CPP Interview Questions And Answers
CPP Interview Questions And Answers
R4R,CPP Objective, CPP Subjective, CPP Interview Questions And Answers,CPP,CPP Interview,CPP Questions ,CPP Answers