Interview Questions

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1. How can you make constructor to return integer.

a. With reference. No return is allowed.


2. There is a function which contains local std::map variable. The function will insert/update/delete
from this map. If there are multiple threads calling this function at the same time, what the best
way to protect it?
a. No protection is required as the variable is a local to that function
3. Can you invoke static function from abstract base class?
a. Yes to invoke static function no object is required.
4. Create 10 bytes of char buffer on heap and delete it.
a. Create should be char *ch = new char[10]; , delete with delete []ch;
b. Delete with [] is required else behavior is not confirmed.
5. Two threads are spawned and one thread created memory on heap for which access is global
can another access it and change.
a. Can access
6. 10 objects of a class with a virtual function is create. How many virtual tables & virtual pointers
are created?
a. 1 virtual table & 10 virtual pointers
7. What is the default access specifier for a struct?
a. Public
8. Can protected members be accessed using dot operator?
a. No
9. What happens when a same thread tries to acquire a mutex lock again?
a. By default it’ll be dead lock. If the mutex is recursive, it will not
10. What happens if virtual keyword is not used while declaring a derived virtual function?
a. No effect/Or it will still be virtual
11. What is the default value is declared/created?
a. Junk value/not predictable
12. When do you make a constructor virtual?
a. Constructor cannot be virtual
13. Can we have a reference as member variables?
a. Yes
14. If a method has local static std::map and more than one thread is doing add/delete/modify, will
there be any problem.
a. Process might crash. To prevent std::map has to be protected.
15. What happens to a process if a NULL pointer is deleted
a. Nothing happens.
16. What is mutable & volatile variables
17. What is inline function
a. The idea behind inline functions is to insert the code of a called function at the point
where thefunction 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.
18. Difference between malloc() & realloc()
19. How to catch any exception.
20. What is copy constructor & why it is used.
21. Class A has 2 integer variables & 3 public methods. When an object is created on stack, which
location memory for member variables created and which location memory for functions is
created.
a. Memory for variables is allocated on stack and no separate memory allocated for
functions.
b. What’s the size of such object.
i. 2 * 4 bytes on 32 bit
22. If you have 100 objects and these objects has to be accessed with indexes, which data structure
can be used.
a. Vector
23. How to overload + operator for strings.
24. How will you determine the number of threads with a given PID on Unix based system.
25. If there is a base class A. class B and C are inherited from class A, if class B wants to access Class
C function what needs to be done?
a. Make BaseClass-A as virtual inherit to avoid compiler error.

You might also like