Top Most C++ Interview Questions Part – 4
1.When does a name clash occur?
A name clash occurs when a name is defined in more than one place. For example.,two different class libraries could give two different classes the same name. If you try to use many class libraries at the same time,there is a fair chance that you will be unable to compile or link the program because of name clashes.
2.What is a dangling pointer?
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.
3.Differentiate between the message and method.
Message:
Objects communicate by sending messages to each other. A message is sent to invoke a method Method:
Provides response to a message. It is an implementation of an operation.
4.What is an adaptor class or Wrapper class?
A class that has no functionality of its own. 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.
5.What is a Null 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.
6.What is class invariant?
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.
7.What do you mean by Stack unwinding?
It 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.
8.What are proxy objects?
Objects that stand for other objects are called proxy objects or surrogates.
9.Name some pure object oriented languages.
Smalltalk,Java,Eiffel,Sather.
10.What is an orthogonal base class?
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.
11.What is the difference between Mutex and Binary semaphore?
semaphore is used to synchronize processes. where as mutex is used to provide synchronization between threads running in the same process
12.What is destructor?
Destructor usually deletes any extra resources allocated by the object.
13.What are C++ storage classes?
auto
register
static
extern
auto:
the default. Variables are automatically created and initialized when they are defined and are destroyed at the end of the block containing their definition. They are not visible outside that block
register:
a type of auto variable. a suggestion to the compiler to use a CPU register for performance
static:
a variable that is known only in the function that contains its definition but is never destroyed and retains its value between calls to that function. It exists from the time the program begins execution
extern:
a static variable whose definition and placement is determined when all object and library modules are combined (linked) to form the executable code file. It can be visible outside the file where it is defined.
14.What is reference ?
reference is a name that acts as an alias,or alternative name,for a previously defined variable or an object.prepending variable with “&” symbol makes it as reference.
for example:
int a;
int &b = a;
15.What are the defining traits of an object-oriented language?
The defining traits of an object-oriented language are:
encapsulation
inheritance
polymorphism
16.What is Quadratic Probing?
The Performance problem encountered by linear probing is caused by the cluster buildup That occurs as a result of the probing sequence.
Quadratic probing uses a different sequence to avoid primary clustering.
17.What is the chaining?
The Chaining technique basically looks at the hash table as an array of pointers to linked lists. Each slot in the hash table is either empty or simply consists of a pointer to a linked list. You resolve collisions by adding the elements that hash to the same slot to the linked list to which that slot points.
At the same time,deletions are easy,You simply delete elements from the linked list.
18.What is the Hash Function?
The hash function is an important part of the hashing technique. This function is used to transform the keys into table addresses. The hash function we choose should be easy to compute and should be able to transform the keys into integers in the range 0 to TR-
1. Because most of the commonly used hash functions are based on arithmetic operations,We should convert the keys to numbers on which arithmetic operations can be performed
19.What is an Visualizations?
The visualization is the basically a way of presentation ,Its just a fancy name for the diagrams,pictures,screen shots,prototypes,and any other visual representations created to help through and design the graphical user interface of your product.
20.What is virtual inheritance?
Inheritance is a basically can be private ,public,or virtual. With virtual inheritance there is only one copy of each object even if the object appears more than once in the hierarchy.
21.What is multithreading
Multithreading is defined as :It is the task of creating a new thread of execution within an existing process rather than starting a new process to begin a function. It is the ability of an operating system to concurrently run programs that have been divided into subcomponents,or threads.
22.What is the use of using?
Using is bassically a namespace scope. Its directive used to declare the accessibility of identifiers declared within a namespace scope.
23.What is the use of exception handling?
Exception handling is bassically used to detect exceptions becouse it can be taken a corresponding action
24.What is EOF?
EOF bassically stands for End of File,It is used to check for the end of file when a file is being read.
25.Define the parameterized macros
Parameterized macros are use for the parameters . It is the one which consist of template with insertion points for the addition of parameters.
26.What is overflow error?
Overflow error basically a type of arithmatic errors.It’s caused by the result of an arithmetic operation being greater than the actual space provided by the system.
27.What is a nested class? Why can it be useful?
Nested classes basically useful for organizing code and controlling access and dependencies. Nested classes obey access rules just like other parts of a class do.and that class is a class enclosed within the scope of another class.
28.What are the disadvantages of C++?
a)It’s not pure object oriented programming language.
b)Its a Platform dependent
c)C++ does not give excellent graphics as compare to java.
d)Its Not case sensitive.
e)C++ have Less features as compared to Java& C#.
f)Its Not applicable in web environment.
g)Does not provide very strong type-checking.
h)c++ code is easily prone to errors related to data types,their conversions.
i)Does not provide efficient means for garbage collection.
j)No built in support for threads
29.What is an iterator?
An iterator is a basically a type of object that represents a stream of data. It is Unlike a sequence,an iterator can only provide the next item. The for-in statement uses iterators to control the loop,and iterators can also be used in many other contexts
30.What is the Auto Storage Class?
Auto Storage Class is basically the default. Variables are automatically created and initialized,When they are defined and are destroyed at the end of the block containing their definition. They are not visible outside that block.