$var(pageTitle)$

1.What is namespace std; and what is consists of ?

Ans:Namespacestd; defines your standard C++ library, it consists of classes, objects and functions of the standard C++ library. You can specify the library by using namespace std or std: : throughout the code. Namespace is used to differentiate the same functions in a library by defining the name.


2.Is C++ a pure object oriented programming language?

Ans:Creation of class or object is optional while creation of main function is mandatory. > We can say that C++ is very close to C and provides optional OOP features. Hence it is semi-object oriented


3.Explain what is multi-threading in C++?

To run two or more programs simultaneously multi-threading is useful. There are two types of • Process-based: It handles the concurrent execution of the program • Thread-based: It deals with the concurrent execution of pieces of the same program


4.Why did we need OOPs/classes when in C we had structs and could achieve the same?

Ans: a short answer might be "Because classes enable inheritance, and inheritance enables many useful paradigms (most importantly polymorphism) that decrease code complexity".


5.What are manipulators ?what is the use of manipulators in c++?

Ans:Manipulators are the functions which can be used in conjunction with the insertion (<<) and extraction (>>) operators on an object. Examples are endl and setw. Manipulators are used to change formatting parameters on streams and to insert or extract certain special characters.


6. What are VTABLE and VPTR?

vtable is a table of function pointers. It is maintained per class. vptr is a pointer to vtable. It is maintained per object (See this for an example). Compiler adds additional code at two places to maintain and use vtable and vptr. 1) Code in every constructor. This code sets vptr of the object being created. This code sets vptr to point to vtable of the class. 2) Code with polymorphic function call (e.g. bp->show() in above code). Wherever a polymorphic call is made, compiler inserts code to first look for vptr using base class pointer or reference (In the above example, since pointed or referred object is of derived type, vptr of derived class is accessed). Once vptr is fetched, vtable of derived class can be accessed. Using vtable, address of derived derived class function show() is accessed and called.


7. What are the features of OOP’s concepts? List them and Explain .

Ans:The main features of OOP’s are: Encapsulation Polymorphism Inheritance Abstraction Encapsulation is referred to one of the following two notions. 1) Data hiding: A language feature to restrict access to members of an object. For example, private and protected members in C++. 2) Bundling of data and methods together: Data and methods that operate on that data are bundled together. Polymorphism means that some code or operations or objects behave differently in different contexts. In C++, following features support polymorphism. Inheritance:The properties of base class are being acquired by child classes. Abstarction:The hiding of data and show only its functionality is known as Abstraction.


8. C++ supports multiple inheritance. What is the “diamond problem” that can occur with multiple inheritance? Give an example.

Ans:It means that we cannot create hybrid inheritance using multiple and hierarchical inheritance. Let’s consider a simple example. A university has people who are affiliated with it. Some are students, some are faculty members, some are administrators, and so on. So a simple inheritance scheme might have different types of people in different roles, all of whom inherit from one common “Person” class. The Person class could define an abstract getRole() method which would then be overridden by its subclasses to return the correct role type. But now what happens if we want to model the role of a Teaching Assistant (TA)? Typically, a TA is both a grad student and a faculty member. This yields the classic diamond problem of multiple inheritance and the resulting ambiguity


9. Is it possible to have a recursive inline function?

Ans: Although you can call an inline function from within itself, the compiler may not generate inline code since the compiler cannot determine the depth of recursion at compile time. A compiler with a good optimizer can inline recursive calls till some depth fixed at compile-time (say three or five recursive calls), and insert non-recursive calls at compile time for cases when the actual depth gets exceeded at run time.


10. What is virtual inheritance in C++?

Ans:Virtual inheritance is a C++ technique that ensures only one copy of a base class's member variables are inherited by grandchild derived classes. ... This feature is most useful for multiple inheritance, as it makes the virtual base a common subobject for the deriving class and all classes that are derived from it.


11. Explain the volatile and mutable keywords.

Ans:The volatile keyword informs the compiler that a variable may change without the compiler knowing it. Variables that are declared as volatile will not be cached by the compiler, and will thus always be read from memory. The mutable keyword can be used for class member variables. Mutable variables are allowed to change from within const member functions of the class.


12. How many times will this loop execute? Explain your answer. unsigned char half_limit = 150;

If you said 300, you would have been correct if i had been declared as an int. However, since i was declared as an unsigned char, the corrct answer is that this code will result in an infinite loop. Here’s why: The expression 2 * half_limit will get promoted to an int (based on C++ conversion rules) and will have a value of 300. However, since i is an unsigned char, it is rerepsented by an 8-bit value which, after reaching 255, will overflow (so it will go back to 0) and the loop will therefore go on forever.


13. What do you mean by internal linking and external linking in c++?

A symbol is said to be linked internally when it can be accessed only from with-in the scope of a single translation unit. By external linking a symbol can be accessed from other translation units as well. This linkage can be controlled by using static and extern keywords.


14. What do you mean by storage classes?

Storage class are used to specify the visibility/scope and life time of symbols(functions and variables). That means, storage classes specify where all a variable or function can be accessed and till what time those variables will be available during the execution of program.


15. Why do we need copy constructor?

Ans:Copy Constructor is called when an object is either passed by value, returned by value, or explicitly copied. If there is no copy constructor, c++ creates a defaultcopy constructor which makes a shallow copy. If the object has no pointers to dynamically allocated memory then shallow copy will do.


16. What you mean by early binding and late binding? How it is related to dynamic binding?

Ans: Binding is the process of linking actual address of functions or identifiers to their reference. This happens mainly two times. During compilation : This is called early binding For all the direct function references compiler will replace the reference with actual address of the method. At runtime : This is called late binding. In case of virtual function calls using a Base reference, as in shown in the example of question no: 2, compiler does not know which method will get called at run time. In this case compiler will replace the reference with code to get the address of function at runtime. Dynamic binding is another name for late binding.


17. What are Visibility Labels in C++?

The keywords Public, Protected and Private are known as Visibility Labels in C++. By default, the members of any Class are private. A Class which has a Visibility label private is completely hidden from the external environment and does not serve any purpose. A Class with Public Label is visible to the other functions and classes.