Sunday, May 18, 2008

C C++ Technical Interview Questions and Tips

C C++ Technical Interview Questions and Tips

Mutable keyword?

1. keyword is the key to make exceptions to const
2. mutable data member is allowed to change during a const member function
3. mutable data member is never const even when it is a member of a const object
4. a const member function may change a mutable member

# Something you can do in C but not in C++?C++ applications generally slower at runtime and compilation - input/output
Difference between calloc and malloc?

1. malloc: allocate s bytes
2. calloc: allocate n times s bytes initialized to 0

# What will happen if I allocate memory using new & free memory using free? WRONG
Difference between printf and sprintf?

1. sprintf: a function that puts together a string, output goes to an array of char instead of stdout
2. printf: prints to stdout

map in STL?

1. used to store key - value pairs, value retrieved using the key
2. store data indexed by keys of any type desire instead of integers as with arrays
3. maps are fast 0(log(n)) insertion and lookup time
4. std::mapEX:Std::map grade_list //grade_list["john"] = b

When will we use multiple inheritance?

1. use it judiciously class
2. when MI enters the design scope it becomes possible to inherit the same name (function/typedef) from more than one base class == ambiguity
3. C++first identifies the function thats the best match for the call
4. C++resolves calls to overload before accessibility, therefore the accessibility of Elec_Gadget() checkout is never evaluated because both are good matches == ERROR
5. resolve ambiguity mp.Borrowable_Item::checkOut(); mp.Elec_Gadget::checkOut(); //error because trying to access private
6. deadly MI diamond: anytime you have an inheritance hierarchy w/ more than one path between a base class and a derived classEX:FileInput File Output FileIOFile//File and IOFile both have paths through InputFile and OutputFile

# Multithreading - C++does not have a notion of multithreading, no notion of concurrency
# Why is the pre-increment operator faster than the post-increment operator? pre is more efficient that post because for post the object must increment itself and then return a temporary containing its old value. True for even built in types
# What is a hash and what would you use it for?
# What is a dot product and what is a cross product - what would you use them for?
# What is 2 ^ 101?