Re: C++ interview questions
arnuld@arch.i-did-not-set--mail-host-address--so-tickle-me wrote:
After1 month from now, I will start giving job interviews. Searchign
at Google led me to several common questions asked in interviewers
looking for C++ based programmers. I have titled it "C++ interview
questions - 1 (technical)" as, after sometime, I will start another
thread titled "C++ interview questions (general)":
I searched for the archives too but didn ot get answers:
1.) Why array index start at 0 (zero) ?
I got these results but I can't know which one is right:
http://groups.google.com/group/comp.lang.c/browse_thread/
thread/73497fc628da3bf5/69c1e93404e86b5c?q=why+array+index+start+at+zero&lnk=ol&
http://groups.google.com/group/comp.lang.c/browse_thread/thread/6aadd2ee93c4283e
/675769f6aa2315ce?lnk=gst&q=why+array+index+start+at+zero#675769f6aa2315ce
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/3323640c835dd407/
e0972682186dcdd9?lnk=gst&q=why+array+index+start+at+zero#e0972682186dcdd9
I didn't look at the given answers, but my guess would be "because
in C it was, and it made sense, so Stroustrup kept it". The person
interviewing you may not go along with the humour, so you could try
"because indexing is done using the 'base address + offset' method,
and the easiest way to calculate the offset is to multiply the index
(which has to start with 0) by the size of the object.
2.) What is RTTI and What is the difference between dynamic_cast and
static_cast ?
That's not a single question.
RTTI means "Run-Time Type Information" and I have no idea about its
definition :(.
It's a mechanism that allows identifying certain types (this making
them distinguishable) in run-time.
dynamic_cast can cast from a base class to a derived class but
static_cast can not do that . Right ?
No, that's not right. static_cast can cast from a base to derived
just as well. The difference is that 'dynamic_cast' can _fail_
because it involves *type checking*. Also, 'dynamic_cast' is
a *run-time* operation, whereas 'static_cast' is the *compile-time*
operation.
3.) How is static variable stored in the memory ?
I got these and they say "It is not defined in the C++ & C Standard":
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/ef9acfeaa4862e4/
8a7afbe1993f2be8?lnk=gst&q=how+static+variable+is+stored+in+memory#8a7afbe1993f2be8
http://groups.google.com/group/comp.lang.c/browse_thread/thread/7812891d697d6897/
fc02e5c49baf0a44?lnk=gst&q=how+static+variable+is+stored+in+memory#fc02e5c49baf0a44
http://groups.google.com/group/comp.lang.c/browse_thread/thread/e5231a596c44a23c/
772e42e38db4f5f7?lnk=gst&q=how+static+variable+is+stored+in+memory#772e42e38db4f5f7
4.) what is an escaping variable?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/18070ad1b1f3e13d/
ddda06e0ed32782b?lnk=gst&q=what+is+escaping+variable#ddda06e0ed32782b
I think in both questions (3rd and 4th ) "Victor Bazarov" is right but
what should I answer in front of an HR ?
Tell him "Victor Bazarov" told you to answer it so :-)
5.) How can you force instantiation of a Template ?
Use an explicit template instantiation. Syntax is similar to a template
declaration (it also begins with the keyword "template" ) but without
the following angle brackets.
6.) What is a Framework in C++ ?
A Framework is not really a C++ term. Any combination of types and
functions designed (and implemented) to serve as the basis to make
some functioning software (with additional business logic) is a kind
of framework. Google for more.
7.) What happens to the member functions in the class when copy
constructor is invoked ?
Huh?
8.) What are the different types of storage classes ?
"Storage classes"? Do you mean standard containers?
9.) What is the difference between function-overloading and
operator-overloading ?
a. Operators have particular meaning.
b. One's not allowed to overload operators for built-in types.
10.) Is there any way to write a class so that no class can be
iinherited from it ?
Yes. See Stroustrup's home page, and his C++ technical FAQ list.
11.) What is the difference between a user-defined object and
standard object ?
Standard objects are few and far between. Like 'std::cout' or
'std::cerr'. When user code begins executing, standard objects
have been already initialised, it's done by the code inside the
Standard library (and it's not defined how it happens). User
objects are initialised by user code.
12.) How to create an object so that it should not call its
constructor by default ?
Who should not call its what? Objects don't call their default
anything. Objects are constructed. It's the execution environment
that calls anything.
Supply arguments for constructing the object.
13.) Is it possible to inherit the private members in derived class ?
Yes, they are all inherited. They are inaccessible, though, unless
the derived class is also a friend.
14.) what is the difference between static global variable and static
local variable ?
The difference is in the time they are initialised, and their scope.
(I always thought that there is nothing like "static global variable")
Any variable declared/defined at the namespace scope is _glogal_.
And it has static storage duration, which makes it static.
15.) What are the types of STL containers ?
There are two: sequencial and associative.
(I think that they are typeless)
Huh?
16.) What are Polymorphic Classes ?
(Classes which are related by polymorphism. It means, they have
similar operations and are derived from some other classes which , in
fact, have inherited the same base class)
That's incorrect. Polymorphic class is one that can be used
polymorphically. In C++ it means it derives from a base class
that has virtual functions.
17.) What do you mean by binding of data and functions ?
Binding is the process of establishing the rigid connection between
the name/address and the object that has meaning (or code that does
some work).
18.) What is the difference between macro and inline() ?
Macros are preprocessor text substitution tools. Inline functions are
compiled constructs (like any other functions).
(A macro bypasses the preprocesses whereas inline() does not)
I don't understand that statement.
19.) What is a memory leak ? How we can avoid it ?
A memory leak is the result of allocating memory and losing any
information about it which would allow freeing it later. To avoid
memory leaks, deallocate all memory you have allocated.
20.) what is the difference between wait() and delay() ?
Those are not C++ terms.
21.) What is the difference a fake pointer and a smart pointer ?
(ouch!, I did not even know that there is a thing called "fake
pointer" )
I don't know what a "fake pointer" is.
Here are some funny interviews questions:
What's so funny about those?
- What is the difference a Function and a Member-Function ?
That is not a complete sentence in English. The difference
_between_ a function and a member function exists and it's not
funny.
- What is the virtual class and friend class ?
No such thing as "virtual class", but there is a "virtual base
class" -- read up on those. Friend class -- open your C++ book
and read.
- What is the difference C and C++ ?
That is not a complete sentence in English. The difference *between*
C and C++ is vast - C++ has many more rules and constructs for object-
oriented and generic progamming.
- What is namespace ?
It is a combination of all names (types, functions, and objects)
declared in it. Namespaces participate in a certain way in name
resolution. Namespace is a mechanism to both bring some names
close together (by containing them in one name resolution region)
and separate them (by containing them in different name resolution
regions). Namespaces help establishing logical boundaries between
sets of names used in the program.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask