1. What is C++..?

Ans:- Released in 1985, C++ is an object-oriented programming language created by Bjarne Stroustrup. C++ maintains almost all aspects of the C language, while simplifying memory management and adding several features – including a new datatype known as a class (you will learn more about these later) – to allow object- oriented programming. C++ maintains the features of C which allowed for low-level memory access but also gives the programmer new tools to simplify memory management.

2. Where C++ used For..?

Ans:- C++ is a powerful general-purpose programming language. It can be used to create small programs or large applications. It can be used to make CGI scripts or console- only DOS programs. C++ allows you to create programs to do almost anything you need to do. The creator of C++, Bjarne Stroustrup, has put together a partial list of applications written in C++.

3. How do you find out if a linked-list has an end..? (i.e. the list is not a cycle)

Ans:-You can find out by using 2 pointers. One of them goes 2 nodes each time. The second one goes at 1 nodes each time. If there is a cycle, the one that goes 2 nodes each time will eventually meet the one that goes slower. If that is the case, then you will know the linked-list is a cycle.

4. What is the difference between realloc() and free()..?

Ans:-The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will occur. The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is not a valid pointer.

5. What is function overloading and operator overloading..?

Ans:-   Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler selects the proper function by examining the number, types and order of the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types.

Operator overloading allows existing C++ operators to be redefined so that they work on objects of user-defined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant facade that doesn’t add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).

6. What is the difference between declaration and definition..?

Ans:-The declaration tells the compiler that at some later point we plan to present the definition of this declaration.

E.g.: void stars () // declarator.


for(int j=10; j > =0; j–) //function body cout << *;

cout <<>

7. What are the advantages of inheritance..?

Ans:-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.

8. How do you write a function that can reverse a linked-list..?

Ans:- Eg:-

void reverselist(void)


if(head==0) return;





head->next = 0;

tail->next = head;




node* pre = head;

node* cur = head->next;

node* curnext = cur->next;

head->next = 0;

cur-> next = head;

for(; curnext!=0; )


cur->next = pre;

pre = cur;

cur = curnext;

curnext = curnext->next;


curnext->next = cur;



9. What do you mean by inline function..?

Ans:-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.

10. Write a program that ask for user input from 5 to 9 then calculate the average..?


#include “iostream.h”

int main() {

int MAX = 4;

int total = 0;

int average;

int numb;

for (int i=0;i


cout << “Please enter your input between 5 and 9: “;

cin >> numb;

while ( numb<5>9) {

cout << “Invalid input, please re-enter: “;

cin >> numb;


total = total + numb;


average = total/MAX;

cout << “The average number is: ” << average << “\n”;

return 0;


11. Write a program that ask for user input from 5 to 9 then calculate the average..?


for( unsigned int i = 1; i < = 100; i++ )

if( i & 0x00000001 )

cout << i << \”,\”;

12. What is public, protected, private..?

Ans:-• 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.

13. Write a function that swaps the values of two integers, using int* as the argument type..?

Ans:-void swap(int* a, int*b) { int t; t = *a; *a = *b; *b = t; }

14. Tell how to check whether a linked list is circular..?

Ans:-Create two pointers, each set to the start of the list. Update each as follows:

while (pointer1) {

pointer1 = pointer1->next;

pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;

if (pointer1 == pointer2) {

print (\”circular\n\”);



Why does this work..?

If a list is circular, at some point pointer2 will wrap around and be either at the item just before pointer1, or the item before that. Either way, it’s either 1 or 2 jumps until they meet.

15. What is polymorphism..?

Ans:-Polymorphism is the idea that a base class can be inherited by several classes. A base class pointer can point to its child class and a base class array can store different child class objects.

16. What is the difference between an ARRAY and a LIST..?

Ans:-Array: User need not have to keep in track of next memory allocation.

List: User has to keep in Track of next location where memory is allocated.

17. What is a template..?

Ans:-Templates allow to create generic functions that admit any data type as parameters and return value without having to overload the function with all the possible data types. Until certain point they fulfill the functionality of a macro. Its prototype is any of the two following ones:

Template function_declaration; template function_declaration;

The only difference between both prototypes is the use of keyword class or typename, its use is indistinct since both expressions have exactly the same meaning and behave exactly the same way.

18. What is constructor ..?

Ans:-Constructor is a member function of the class, with the name of the function being the same as the class name. It also specifies how the object should be initialized.

19. What is RTTI..?

Ans:-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.

20. What is encapsulation..?

Ans:-Packaging an object’s variables within its methods is called encapsulation.

Explain term POLIMORPHISM and give an example using eg. SHAPE object: If I have a base class SHAPE, how would I define DRAW methods for two objects CIRCLE and SQUARE.

21. What is an object..?

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

22. What is namespace..?

Ans:-Namespaces allow us to group a set of global classes, objects and/or functions under a name. To say it somehow, they serve to split the global scope in sub-scopes known as namespaces.

23. What do you mean by inheritance..?

Ans:-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.

24. What is a COPY CONSTRUCTOR and when is it called..?

Ans:-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:

25. What is Boyce Codd Normal form..?

Ans:-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

26. What is virtual class and friend class..?

Ans:-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.

27. What is the difference between an object and a class..?

Ans:-Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.

– A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don’t change.

– The class to which an object belongs is also (usually) static. If a particular object belongs to a certain class at the time that it is created then it almost certainly will still belong to that class right up until the time that it is destroyed.

– An Object on the other hand has a limited lifespan. Objects are created and eventually destroyed. Also during that lifetime, the attributes of the object may undergo significant change.

29. What is a class..?

Ans:-Class is a user-defined data type in C++. It can be created to solve a particular kind of problem. After creation the user need not know the specifics of the working of a class.

30. What is friend function..?

Ans:-As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be listed in the class definition.

31. What is abstraction..?

Ans:-Abstraction is of the process of hiding unwanted details from the user.

32. What are virtual functions..?

Ans:-A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don’t know about the derived class.

33. What is a scope resolution operator..?

Ans:-A scope resolution operator (::), can be used to define the member functions of a class outside the class.

34.What do you mean by pure virtual functions..?

Ans:-A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero. class Shape { public: virtual void draw() = 0; };.

35. What’s the best way to declare and define global variables..?

Ans:-The best way to declare global variables is to declare them after including all the files so that it can be used in all the functions..

36.What does extern mean in a function declaration..?

Ans:-Using extern in a function declaration we can make a function such that it can used outside the file in which it is defined.

An extern variable, function definition, or declaration also makes the described variable or function usable by the succeeding part of the current source file. This declaration does not replace the definition. The declaration is used to describe the variable that is externally defined.

If a declaration for an identifier already exists at file scope, any extern declaration of the same identifier found within a block refers to that same object. If no other declaration for the identifier exists at file scope, the identifier has external linkage.

37. What’s the auto keyword good for..?

Ans:-Not much. It declares an object with automatic storage duration. Which means the object will be destroyed at the end of the objects scope. All variables in functions that are not declared as static and not dynamically allocated have automatic storage duration by default.

For Example :-

int main()


int a; //this is the same as writing “auto int a;”


38. What does extern mean in a function declaration..?

Ans:-It tells the compiler that a variable or a function exists, even if the compiler hasn’t yet seen it in the file currently being compiled. This variable or function may be defined in another file or further down in the current file.

39. Explain the scope resolution operator..?

Ans:-It permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.

40. What is a conversion constructor..?

Ans:-A constructor that accepts one argument of a different type.

41. What is the difference between a copy constructor and an overloaded assignment operator..?

Ans:-A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.

42. When should you use multiple inheritance..?

Ans:-There are three acceptable answers: “Never,” “Rarely,” and “When the problem domain cannot be accurately modeled any other way.”

43. What is a mutable member..?

Ans:-One that can be modified by the class even when the object of the class or the member function doing the modification is const.

44. What is an explicit constructor..?

Ans:-A conversion constructor declared with the explicit keyword. The compiler does not use an explicit constructor to implement an implied conversion of types. It’s purpose is reserved explicitly for construction.

45. What is the Standard Template Library (STL)..?

Ans:-A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification. A programmer who then launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher than average understanding of the new technology that STL brings to C++ programming.