December 15, 2014

C++ Interview Questions and Answers for Freshers

Basic C++ Questions And Answer, basic c++ interview questions and answers, basic c++ interview questions and answers for freshers, c++ questions and answers for exam, c++ questions for computer science 

Basic CPP Questions
Basic C++ Questions And Answer

C++ Interview Questions and Answers for Freshers 


1 : Why C++ is called object oriented programming language?

Ans : Because C++ supports OOPs features eg: Data encapsulation, data hiding, data abstraction, inheritance, polymorphism, exception handling, message passing.


2 : Difference between method overloading and method overriding in C++?

Ans : Overloading is a function or method performing additional task in addition to the normal task. i.e Same function handles more than one task. Overriding is a method is rewritten in the base class. In this is done using inheritance.


3 : What type of method can be overridden in C+ +?

Ans : In C++ methods with access specifier public can be overridden.


4 : Write a program to illustrate method overriding in C++?


# include <iostream.h>
Void sum();
Void sum(int);
Void sum(float);
Void sum(int, float);
Void main(){
Int f,s;
Float f1,f2;
clrscr();
cout<<”Enter any 2 intergers:”;
cin>>f>>s;
cout<<”Enter any two float numbers;”;
cin>>f1>>f2;
sum();
sum(f);
sum(f,s);
sum(f1,f2);
}
Void sum(){
Int x,y;
Cout<<”Enter any 2 no:”;
Cin>>x>> y;
Cout<<”Sum vlue=”<<x+y<<endl;
}
Void sum(int x){
Cout<<”Sum vlue=”<<x+x<<endl;
}
}//same way you can add other methods


5 : Difference between an object and a class?

Ans : Class is a collection of data members and methods. Object is an instance of a class. In brief object is a memory space where all the data members and member functions will be loaded.


 6 : What is memory leaking in C++ ?

Ans : A memory leak is the situation that occurs when dynamically allocation is used u\without handling properly.


7 : What are the things contains in .obj file ?

Ans : When a C++ program is compiled, the program will be executed and an object file is created which contains all data and suitable linking files in machine understandable language.


8 : In C++ have a default constructor?

Ans : Yes, compiler creates the default constructor only and only if the class doesn’t contain any constructor.


9 : What is inline function in C++?

Ans : Inline is a new topic in C++, When we initialize a function inline and call it in main() then instead of moving the control from calling function to called function, the function body will include at the function calling. Main purpose of Inline function is to improve the program performance. It is recommended not to use inline with long code programs.

10 : What is Dynamic memory allocation?

Ans : int m[10]={1,2,3,4};
In the above example occupied memory is 10*2 =20 bytes but actually we are using only 4*2 = 8 bytes so 12 bytes of memory is wasted. To stop this wastage of memory we use dynamic memory allocation concept. This will dynamically allocate the memory to the space we used. Syntax for Dynamic memory allocation: <pointer variable>=new <data type> [size of array];


11 : What is friend function in C++?

Ans : In C++ by default private data can assess only by members of that class but it is not possible to access outside the class functions. This is possible by friend function. friend function mean it is not a member of that class but can access private data of the class. Just you need to add friend in front of method.


12 : Which has more priority (.) or (*)?

Ans : Dot(.) operator has more priority than asterisk (*). Using brackets we can implicitly apply * for operands when needed.

No comments:
Write comments