InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 151. |
Can You Be Able To Identify Between Straight- Through And Cross- Over Cable Wiring? And In What Case Do You Use Straight- Through And Cross-over? |
|
Answer» Straight-through is type of wiring that is ONE to connection, CROSS- over is type of wiring which those wires are got switched We use Straight-through cable when we connect between NIC ADAPTER and Hub. Using Cross¬over cable when connect between two NIC Adapters or sometime between two HUBS. Straight-through is type of wiring that is one to connection, Cross- over is type of wiring which those wires are got switched We use Straight-through cable when we connect between NIC Adapter and Hub. Using Cross¬over cable when connect between two NIC Adapters or sometime between two hubs. |
|
| 152. |
If You Hear The Cpu Fan Is Running And The Monitor Power Is Still On, But You Did Not See Anything Show Up In The Monitor Screen. What Would You Do To Find Out What Is Going Wrong? |
|
Answer» I would use the ping command to check WHETHER the machine is still ALIVE(connect to the NETWORK) or it is DEAD. I would use the ping command to check whether the machine is still alive(connect to the network) or it is dead. |
|
| 153. |
Assignment Operator - What Is The Diffrence Between A "assignment Operator" And A "copy Constructor"? |
|
Answer» In ASSIGNMENT operator, you are ASSIGNING a value to an EXISTING object. But in copy constructor, you are CREATING a new object and then assigning a value to that object. In assignment operator, you are assigning a value to an existing object. But in copy constructor, you are creating a new object and then assigning a value to that object. |
|
| 154. |
Rtti - What Is Rtti In C++? |
|
Answer» RTTI STANDS for "RUN Time Type Identification". In an INHERITANCE hierarchy, we can find out the EXACT type of the objet of which it is member. It can be done by using:
RTTI stands for "Run Time Type Identification". In an inheritance hierarchy, we can find out the exact type of the objet of which it is member. It can be done by using: |
|
| 155. |
Stl Containers - What Are The Types Of Stl Containers? |
|
Answer» There are 3 TYPES of STL containers:
There are 3 types of STL containers: |
|
| 156. |
Describe Private, Protected And Public - The Differences And Give Examples. |
|
Answer» ANSWER : class Point2D{ int x; int y; public int color; protected bool pinned; public Point2D():x(0),y(0){} //default(no argument) CONSTRUCTOR }; Point2D MyPoint; You cannot directly access private data members when they are DECLARED (implicitly) private: MyPoint.x = 5; // Compiler will issue a compile ERROR //Nor YOY can see them: int xdim = MyPoint.x; // Compiler will issue a compile ERROROn the other hand, you can ASSIGN and read the public data members: MyPoint.color = 255; //no problem int col = MyPoint.color; // no problemWith protected data members you can read them but not write them: bool isPinned = MyPoint.pinned; // no problem.You cannot directly access private data members when they are declared (implicitly) private: On the other hand, you can assign and read the public data members: With protected data members you can read them but not write them: |
|
| 157. |
What Is A C++ Object? |
|
Answer» OBJECT is a SOFTWARE bundle of variables and related methods. OBJECTS have STATE and behavior. Object is a software bundle of variables and related methods. Objects have state and behavior. |
|
| 158. |
What Is Encapsulation In C++? |
|
Answer» Packaging an object's VARIABLES within its METHODS is CALLED ENCAPSULATION. Packaging an object's variables within its methods is called encapsulation. |
|
| 159. |
What Is Rtti In C++? |
|
Answer» 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. 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. |
|
| 160. |
What Is The Difference Between Class And Structure In C++? |
|
Answer» Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by DEFAULT PUBLIC. Class: Class is a SUCCESSOR of Structure. By default all the MEMBERS inside the class are private. Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. Class: Class is a successor of Structure. By default all the members inside the class are private. |
|
| 161. |
You Have Two Pairs: New() And Delete() And Another Pair : Alloc() And Free(). Explain Differences Between Eg. New() And Malloc() |
Answer»
|
|
| 162. |
Define A Constructor - What It Is And How It Might Be Called (2 Methods). |
|
Answer» 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.
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. |
|
| 163. |
What Is A Template In C++? |
|
Answer» 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 <class indetifier> functiondeclaration; template <typename indetifier> functiondeclaration; 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. 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 <class indetifier> functiondeclaration; template <typename indetifier> functiondeclaration; 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. |
|
| 164. |
Does C++ Support Multilevel And Multiple Inheritance? |
|
Answer» Yes. Yes. |
|
| 165. |
What Is The Difference Between An Array And A List? |
Answer»
|
|
| 166. |
What Is Virtual Constructors/destructors? |
|
Answer» VIRTUAL destructors: If an OBJECT (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is called on the object. There is a SIMPLE solution to this problem declare a virtual base-class destructor. This makes all derived-class destructors virtual even THOUGH they don't have the same name as the base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator to a base-class pointer to a derived-class object, the destructor for the appropriate class is called. Virtual constructor: Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax ERROR. Virtual destructors: If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is called on the object. There is a simple solution to this problem declare a virtual base-class destructor. This makes all derived-class destructors virtual even though they don't have the same name as the base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator to a base-class pointer to a derived-class object, the destructor for the appropriate class is called. Virtual constructor: Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error. |
|
| 167. |
Write A Function That Swaps The Values Of Two Integers, Using Int* As The Argument Type? |
|
Answer» Answer :void SWAP(INT* a, int*B) { INTT; t=*a; *a = *b; *b = t; } |
|
| 168. |
What Is Public, Protected, Private In C++? |
Answer»
|
|
| 169. |
Write A Short Code Using C++ To Print Out All Odd Number From 1 To 100 Using A For Loop |
|
Answer» Answer :for( unsigned INT i = 1; i < = 100; i++ ) if( L & 0x00000001 ) cout«i«","; |
|
| 170. |
Write A Program That Ask For User Input From 5 To 9 Then Calculate The Average? |
|
Answer» Answer : #INCLUDE "iostream.h" intmain() { intMAX = 4; int total = 0; int average; int numb; for (int i=0; KMAX; i++) { cout« "Please enter your INPUT between 5 and 9: "; cin » numb; while (numb<5 || numb>9) { cout« "Invalid input, please re-enter: "; cin » numb; } total = total + numb; } average = total/MAX; cout« "The average number is: " « average « "n"; RETURN 0; } |
|
| 171. |
What Do You Mean By Inline Function? |
|
Answer» 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. 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. |
|
| 172. |
How Do You Write A Function That Can Reverse A Linked-list? |
|
Answer» Answer : void reverselist(void) { if(HEAD==0) RETURN; if(head->next==0) return; if(head->next==tail) { head->next = 0; tail->next = head; } else { 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; } } |
|
| 173. |
What Are The Advantages Of Inheritance In C++? |
|
Answer» 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. 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. |
|
| 174. |
What Is The Difference Between Declaration And Definition? |
|
Answer» The declaration tells the COMPILER that at some LATER point we plan to PRESENT the definition of this declaration. The declaration tells the compiler that at some later point we plan to present the definition of this declaration. |
|
| 175. |
What Is Function Overloading And Operator Overloading? |
|
Answer» 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). 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). |
|
| 176. |
What Is The Difference Between Realloc() And Free()? |
|
Answer» 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. 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. |
|
| 177. |
In The Derived Class, Which Data Member Of The Base Class Are Visible? |
|
Answer» In the PUBLIC and PROTECTED SECTIONS. In the public and protected sections. |
|
| 178. |
What Is The Two Main Roles Of Operating System? |
| Answer» | |
| 179. |
How Do You Traverse A Btree In Backward In-order? |
| Answer» | |
| 180. |
Write A Struct Time Where Integer M, H, S Are Its Members |
| Answer» | |
| 181. |
What Is Pure Virtual Function? |
|
Answer» A class is MADE ABSTRACT by declaring one or more of its virtual functions to be pure. A pure virtual FUNCTION is one with an initializer of = 0 in its DECLARATION. A class is made abstract by declaring one or more of its virtual functions to be pure. A pure virtual function is one with an initializer of = 0 in its declaration. |
|
| 182. |
What Is Boyce Codd Normal Form? |
|
Answer» 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->b, where a and b is a subset of R, at least one of the following holds:
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->b, where a and b is a subset of R, at least one of the following holds: |
|
| 183. |
How Can You Tell What Shell You Are Running On Unix System? |
|
Answer» You can do the Echo $RANDOM. It will return a undefined variable if you are from the C-Shell, just a return PROMPT if you are from the BOURNE shell, and a 5 DIGIT random numbers if you are from the Korn shell. You could also do a PS -1 and look for the shell with the highest P(K). You can do the Echo $RANDOM. It will return a undefined variable if you are from the C-Shell, just a return prompt if you are from the Bourne shell, and a 5 digit random numbers if you are from the Korn shell. You could also do a ps -1 and look for the shell with the highest P(K). |
|
| 184. |
How Do You Find Out If A Linked-list Has An End? (i.e. The List Is Not A Cycle) |
|
Answer» 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. 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. |
|
| 185. |
What Is Polymorphism In C++? |
|
Answer» POLYMORPHISM in C++ 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. Polymorphism in C++ 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. |
|
| 186. |
How Do You Write A Function That Can Reverse A Linked-list In C++? |
|
Answer» ANSWER : void reverselist(void) { if(head==0) return; if(head-<NEXT==0) return; if(head-<next==tail) { head-<next = 0; tail-<next = head; } else { 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; } } |
|
| 187. |
What Is A Container Class? What Are The Types Of Container Classes In C++? |
|
Answer» A CONTAINER class is a class that is used to hold objects in memory or external storage. A container class acts as a GENERIC holder. A container class has a predefined behavior and a well-known interface. A container class is a supporting class whose purpose is to hide the topology used for maintaining the LIST of objects in memory. When a container class contains a GROUP of mixed objects, the container is called a HETEROGENEOUS container; when the container is holding a group of objects that are all the same, the container is called a homogeneous container. A container class is a class that is used to hold objects in memory or external storage. A container class acts as a generic holder. A container class has a predefined behavior and a well-known interface. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory. When a container class contains a group of mixed objects, the container is called a heterogeneous container; when the container is holding a group of objects that are all the same, the container is called a homogeneous container. |
|
| 188. |
What Is An Orthogonal Base Class In C++? |
|
Answer» If TWO base classes have no overlapping methods or data they are said to be independent of, or orthogonal to each other. Orthogonal in the sense means that two classes operate in different dimensions and do not interfere with each other in any WAY. The same derived CLASS may INHERIT such classes with no difficulty. If two base classes have no overlapping methods or data they are said to be independent of, or orthogonal to each other. Orthogonal in the sense means that two classes operate in different dimensions and do not interfere with each other in any way. The same derived class may inherit such classes with no difficulty. |
|
| 189. |
What Is A Node Class In C++? |
|
Answer» A node class is a class that,
A node class is a class that has added new services or functionality beyond the services inherited from its base class. A node class is a class that, A node class is a class that has added new services or functionality beyond the services inherited from its base class. |
|
| 190. |
Name Some Pure Object Oriented Languages? |
|
Answer» pure object oriented LANGUAGES are Smalltalk, JAVA, EIFFEL, Sather. pure object oriented languages are Smalltalk, Java, Eiffel, Sather. |
|
| 191. |
What Are Proxy Objects In C++? |
|
Answer» Objects that stand for other objects are called proxy objects or surrogates. template <CLASS t=""> class Array2D { public: class Array ID { public: T&operator[](int INDEX); const T&operator[](int index)const; }; Array ID operator[] (int index); const Array ID operator[] (int index) const; };The following then becomes legal: Array2D<float>data(l0,20); COUT«data[3][6]; // fineHere data[3] yields an ArraylD OBJECT and the operator [] invocation on that object yields the float in position(3,6) of the ORIGINAL two dimensional array. Clients of the Array 2D class need not be aware of the presence of the ArraylD class. Objects of this latter class stand for one-dimensional array objects that, conceptually, do not exist for clients of Array2D. Such clients program as if they were using real, live, two-dimensional arrays. Each ArraylD object stands for a one-dimensional array that is absent from a conceptual model used by the clients of Array2D. In the above example, ArraylD is a proxy class. Its instances stand for one-dimensional arrays that, conceptually, do not exist. Objects that stand for other objects are called proxy objects or surrogates. The following then becomes legal: Here data[3] yields an ArraylD object and the operator [] invocation on that object yields the float in position(3,6) of the original two dimensional array. Clients of the Array 2D class need not be aware of the presence of the ArraylD class. Objects of this latter class stand for one-dimensional array objects that, conceptually, do not exist for clients of Array2D. Such clients program as if they were using real, live, two-dimensional arrays. Each ArraylD object stands for a one-dimensional array that is absent from a conceptual model used by the clients of Array2D. In the above example, ArraylD is a proxy class. Its instances stand for one-dimensional arrays that, conceptually, do not exist. |
|
| 192. |
What Are The Conditions That Have To Be Met For A Condition To Be An Invariant Of The Class? |
| Answer» | |
| 193. |
Define Pre-condition And Post-condition To A Member Function In C++? |
|
Answer» PRECONDITION: A precondition is a condition that must be true on entry to a member function. A class is used correctly if preconditions are never false. An operation is not responsible for doing anything sensible if its precondition fails to hold. For EXAMPLE, the interface invariants of stack class say nothing about pushing yet another element on a stack that is already FULL. We say that isful() is a precondition of the push operation. Post-condition: A post-condition is a condition that must be true on EXIT from a member function if the precondition was valid on entry to that function. A class is implemented correctly if post-conditions are never false. For example, after pushing an element on the stack, we know that isempty() must necessarily hold. This is a post-condition of the push operation. Precondition: A precondition is a condition that must be true on entry to a member function. A class is used correctly if preconditions are never false. An operation is not responsible for doing anything sensible if its precondition fails to hold. For example, the interface invariants of stack class say nothing about pushing yet another element on a stack that is already full. We say that isful() is a precondition of the push operation. Post-condition: A post-condition is a condition that must be true on exit from a member function if the precondition was valid on entry to that function. A class is implemented correctly if post-conditions are never false. For example, after pushing an element on the stack, we know that isempty() must necessarily hold. This is a post-condition of the push operation. |
|
| 194. |
What Do You Mean By Stack Unwinding In C++? |
|
Answer» Stack unwinding in C++ is a process during EXCEPTION handling when the DESTRUCTOR is called for all local objects between the place where the exception was thrown and where it is CAUGHT. Stack unwinding in C++ is a process during exception handling when the destructor is called for all local objects between the place where the exception was thrown and where it is caught. |
|
| 195. |
What Is Class Invariant In C++? |
|
Answer» A class invariant is a CONDITION that defines all valid STATES for an object. It is a logical condition to ENSURE the correct working of a class. Class invariants must hold when an object is created, and they must be preserved under all operations of the class. In particular all class invariants are both PRECONDITIONS and post-conditions for all operations or member FUNCTIONS of the class. A class invariant is a condition that defines all valid states for an object. It is a logical condition to ensure the correct working of a class. Class invariants must hold when an object is created, and they must be preserved under all operations of the class. In particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class. |
|
| 196. |
What Is A Null Object In C++? |
|
Answer» It is an OBJECT of some class whose purpose is to indicate that a real object of that class does not exist. One common USE for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot FIND such an object. It is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object. |
|
| 197. |
What Is An Adaptor Class Or Wrapper Class In C++? |
|
Answer» A CLASS that has no functionality of its own is an Adaptor class in C++. Its member functions hide the USE of a third party software component or an object with the non-compatible INTERFACE or a non-object-oriented IMPLEMENTATION. A class that has no functionality of its own is an Adaptor class in C++. Its member functions hide the use of a third party software component or an object with the non-compatible interface or a non-object-oriented implementation. |
|
| 198. |
Differentiate Between The Message And Method In C++? |
|
Answer» Message in C++ : Method in C++ :
Message in C++ : Method in C++ : |
|
| 199. |
What Is A Dangling Pointer In C++? |
|
Answer» A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic VARIABLES from a function or using the address of the memory BLOCK after it is FREED. The following code snippet shows this: class Sample { PUBLIC:int *ptr; Sample(int i) { ptr = NEW int(i); } ~Sample() { delete ptr; } void PrintValO { cout« "The value is " « *ptr; } }; void SomeFunc(Sample x) { cout« "Say i am in someFunc " « endl; } int main() { Sample si = 10; SomeFunc(sl); sl.PrintVal(); }In the above example when PrintVal() function is called it is called by the pointer that has been freed by the destructor in SomeFunc.
A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed. The following code snippet shows this: In the above example when PrintVal() function is called it is called by the pointer that has been freed by the destructor in SomeFunc.
|
|
| 200. |
What Is An Incomplete Type In C++? |
|
Answer» Incomplete types REFERS to POINTERS in which there is non availability of the implementation of the referenced location or it points to some location WHOSE value is not AVAILABLE for modification. int *i=0x400 //i points to address 400 *i=0; //set the value of memory location pointed by i.Incomplete types are otherwise called uninitialized pointers. Incomplete types refers to pointers in which there is non availability of the implementation of the referenced location or it points to some location whose value is not available for modification. Incomplete types are otherwise called uninitialized pointers. |
|