C++ interview questions

A

arnuld

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


2.) What is RTTI and What is the difference between dynamic_cast and
static_cast ?

RTTI means "Run-Time Type Information" and I have no idea about its
definition :(.

dynamic_cast can cast from a base class to a derived class but static_cast
can not do that . Right ?



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 ?


5.) How can you force instantiation of a Template ?

6.) What is a Framework in C++ ?

7.) What happens to the member functions in the class when copy
constructor is invoked ?

8.) What are the different types of storage classes ?

9.) What is the difference between function-overloading and
operator-overloading ?

10.) Is there any way to write a class so that no class can be
iinherited from it ?

11.) What is the difference between a user-defined object and standard
object ?

12.) How to create an object so that it should not call its constructor
by default ?

13.) Is it possible to inherit the private members in derived class ?

14.) what is the difference between static global variable and static
local variable ?

(I always thought that there is nothing like "static global variable")


15.) What are the types of STL containers ?

(I think that they are typeless)


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)


17.) What do you mean by binding of data and functions ?

18.) What is the difference between macro and inline() ?

(A macro bypasses the preprocesses whereas inline() does not)

19.) What is a memory leak ? How we can avoid it ?

20.) what is the difference between wait() and delay() ?

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" )



Here are some funny interviews questions:


- What is the difference a Function and a Member-Function ?
- What is the virtual class and friend class ?
- What is the difference C and C++ ?
- What is namespace ?
 
V

Victor Bazarov

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
 
J

Juha Nieminen

Searchign at
Google led me to several common questions asked in interviewers looking
for C++ based programmers.

Many of these questions seem to ask for very specific terminology
which can be, IMO, somewhat irrelevant. I have programmed professionally
in C++ for many years (as a hobby for much longer) and I'm pretty
confident I'm a quite capable C++ coder, yet I probably wouldn't get
even half of these questions right.
1.) Why array index start at 0 (zero) ?

I can guess the reason for this, but is it really all that relevant to
know *why* array indexing starts from 0?

(Array indexing in C++ is directly inherited from array indexing in C,
and the origin for this form of indexing is most probably related to the
origins of C, which was little more than a "wrapper around asm", and in
most CPU architectures of the time (and even today) array indexing in
assembler is zero-based. However, why would this be relevant to know?)
3.) How is static variable stored in the memory ?

Is that really relevant information? I think it's more important to
know how a static variable behaves and how it's used.
4.) what is an escaping variable?

I have no idea. I bet it's something I know, but that term is
something I have never heard.
6.) What is a Framework in C++ ?

By commonly established definition of the word "framework" in
programming languages, or something else?
7.) What happens to the member functions in the class when copy
constructor is invoked ?

Is this a trick question? Or perhaps a badly formulated question,
because I really don't understand what is it that is being really asked
here.
8.) What are the different types of storage classes ?

Strange terminology. I probably know the answer if I knew what is
meant with those terms.
9.) What is the difference between function-overloading and
operator-overloading ?

Odd question. The syntax?
11.) What is the difference between a user-defined object and standard
object ?

Depends on what a "standard object" is. Again, odd terminology. I
probably would know what to answer if I understood the terms.
13.) Is it possible to inherit the private members in derived class ?

Is this also a trick question, or a badly formulated one?

Naturally private members are always inherited (which would make this
a trick question). Perhaps what the question intends to ask is whether
it's possible to *access* private members of the base class from the
derived class (in which case this is a badly formulated question)?
15.) What are the types of STL containers ?

I think this question needs to be more specific. It's too vague. It's
not at all clear what exactly is it that it's asking.
16.) What are Polymorphic Classes ?

This is probably a good question, but I have to admit that I'm not
100% how exactly polymorphism is defined in C++. It's either a class
which has virtual functions, or a template class, or both. (Maybe
classes with virtual functions and template classes are considered
different types of polymorphism?)
17.) What do you mean by binding of data and functions ?

Maybe this question is referring to "dynamic binding"?
18.) What is the difference between macro and inline() ?

There's no such a thing as "inline()". There's a keyword called
"inline", without any parentheses.

Maybe the question should be formulated as "what is the difference
between a macro and an inline function"?
19.) What is a memory leak ? How we can avoid it ?

Whoa, from very specific questions about tiny obscure (and mostly
irrelevant) implementation details of some features to a concept which
would require an entire book to explain fully...

OTOH, I could summarize the book with one word: Encapsulation.
(Of course explaining what that means would require that book...)
20.) what is the difference between wait() and delay() ?

That depends a lot on the computer architecture you are using. Not
really a C++ question.
21.) What is the difference a fake pointer and a smart pointer ?

I have no idea what a fake pointer is, so I couldn't answer this question.
Here are some funny interviews questions:

- What is the difference a Function and a Member-Function ?
- What is the virtual class and friend class ?
- What is the difference C and C++ ?
- What is namespace ?

Why are these funny?
 
Y

yanlinlin

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&ln­k=ol&http://groups.google.com/group/comp.../group/comp.lang.c++/browse_thread/thread/332...
e0972682186dcdd9?lnk=gst&q=why+array+index+start+at+zero#e0972682186dcdd9

  2.) What is RTTI and What is the difference between dynamic_cast and
  static_cast ?

RTTI means "Run-Time Type Information" and I have no idea about its
definition :(.

dynamic_cast can cast from a base class to a derived class but static_cast
can not do that . Right ?

   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/ef9...
8a7afbe1993f2be8?lnk=gst&q=how+static+variable+is+stored+in+memory#8a7afbe1­993f2be8http://groups.google.com/group/comp.lang.c/browse_thread/thread/78128...
fc02e5c49baf0a44?lnk=gst&q=how+static+variable+is+stored+in+memory#fc02e5c4­9baf0a44http://groups.google.com/group/comp.lang.c/browse_thread/thread/e5231...
772e42e38db4f5f7?lnk=gst&q=how+static+variable+is+stored+in+memory#772e42e3­8db4f5f7

   4.) what is an escaping variable?

http://groups.google.com/group/comp.lang.c++/browse_thread/thread/180...
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 ?

  5.) How can you force instantiation of a Template ?  

  6.) What is a Framework in C++ ?

  7.) What happens to the member functions in the class when copy
  constructor is invoked ?

  8.) What are the different types of storage classes ?

  9.) What is the difference between function-overloading and
  operator-overloading ?

  10.) Is there any way to write a class so that no class can be
  iinherited from it ?

  11.) What is the difference between a user-defined object and standard
  object ?

  12.) How to create an object so that it should not call its constructor
 by default ?

  13.) Is it possible to inherit the private members in derived class ?

  14.) what is the difference between static global variable and static
  local variable ?

 (I always thought that there is nothing like "static global variable")

  15.) What are the types of STL containers ?

(I think that they are typeless)

  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)

  17.) What do you mean by binding of data and functions ?

  18.) What is the difference between macro and inline() ?

(A macro bypasses the preprocesses whereas inline() does not)

  19.) What is a memory leak ? How we can avoid it ?

  20.) what is the difference between wait() and delay() ?

  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" )

Here are some funny interviews questions:

 - What is the difference a Function and a Member-Function ?
 - What is the virtual class and friend class ?
 - What is the difference C and C++ ?
 - What is namespace ?

I think some of these questions are not so good for a job interview.
And maybe this conversation is off-topic.
 
V

Victor Bazarov

yanlinlin said:
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 think some of these questions are not so good for a job interview.
And maybe this conversation is off-topic.

No specific set of questions is good for a job interview.

If you learn to answer *only* those, it can very easily be figured
out. Then you're toast.

If you can answer those and any other question (right or not, does
not matter), there is no sense in wasting time figuring out answers
to specifically those. You sink or swim depending on the fraction
of the questions you do get right, but *more importantly* on the
attitude, demeanor, ability to adjust, ability to solve problems,
ability to reason, ability to admit mistakes, etc.

If you know all the right answers to all possible questions, you
know the language. But it's just a notch on the belt. It is still
up to the interviewer (and the manager) to see if they value the
knowledge of the language and how much.

Just like in the old quote from a famous basketball coach, when he
said to his scouts: "Bring me tall guys. It doesn't matter where
their basketball skill level's at. I can always teach guys to play
basketball. I can't teach guys to grow". If you fit their idea
of a good employee, it [almost] doesn't matter that you don't know
certain things in C++. You can always teach a good employee how to
program in C++. You can't teach a C++ programmer who is a jerk
to not be a jerk.

V
 
E

Eric Johnson

To add to what the others have replied, I would recommend that rather
than trying to memorize the answers to these questions, get a good
book like "Effective C++" and read it from cover to cover. (Have
Stroustrup's "The C++ Programming Language" or another comprehensive
text handy to fill in details.) Keep your list of interview questions
in mind as you read the book. By the time you finish, you'll be much
better off than memorizing answers.
 
S

Sam

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:

[snip long list of questions]

I don't understand something. Presumably you're going to be quizzing your
potential C++ job applicants on their knowledge.

Shouldn't that mean that you are supposed to know MORE than them, and that
you'd know the answers to these silly questions?


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBHzJbxx9p3GYHlUOIRAuVcAJ9VmClqBruUfia9fTrAZiwE9ovqFgCfVqDT
bbSt8RPaWofmp7JZCxGfrdc=
=gjuL
-----END PGP SIGNATURE-----
 
J

James Kanze

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.

My reaction would be that in C++, they don't have to be:).
Although they are for the components of the standard library, my
pre-standard array classes followed the Pascal approach: you
specify the upper and lower bounds. Although unlike Pascal, I
used a half open interval, with the upper bounds exclusive.

A more interesting question would be why the lower bound should
be 0 in most cases, even when you have a choice.

[...]
However the compiler likes?

That's a good example of the sort of question that makes no
sense.

Exactly.

This reminds me of a question I once got in an interview: what
does the keyword static mean in C++. The answer they were
looking for was "not on the stack". That answer never occured
to me, and because of that, I didn't get the job. (I'm willing
to bet, however, that I was more competent than whoever finally
did get it.)
Tell him "Victor Bazarov" told you to answer it so :)

I'll admit that I'd draw a blank on this one. I've never heard
of the term.

I don't guess I'd get this job either, if I were a candidate.
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.

Or just use the template, period. If you call a template
function, it's going to be instantiated. If you definie a
variable with a class template type, the template is going to be
instantiated.

The question sounds a bit too vague to me.
A Framework is not really a C++ term.

Which isn't a reason not to ask it. In my experience, questions
about design and patterns are generally more important than
those which directly concern C++.

[...]

Yes, what happens to them? Another question to which I don't
know the answer.
"Storage classes"? Do you mean standard containers?

In the standard, storage class specifiers has a very precise
definition: one of register, static, extern or mutable. If
being perfectly fluent in standardese is an important
qualification for the job, then this is a good question, and you
just failed. The exact answer is rather irrelevant for most C++
programming jobs, however.

If I really wanted to ask something along these lines, it would
be more like "what are the different storage durations supported
by C++, and give an example of an object which has each." Or
even: "what is the difference between storage duration and
object lifetime" (although that to is edging very near just
being an explination of standardese).
a. Operators have particular meaning.
b. One's not allowed to overload operators for built-in types.

The name of the functions have a different syntax, and
overloaded operators can also be called with a different syntax.
For extra credit: with overloaded operators, the overload set
can include both member and non-member functions; for an
overloaded function, it will always be one or the other.
Yes. See Stroustrup's home page, and his C++ technical FAQ list.

Nice piece of trivia, but not interesting for an interview
question.

[...]
Who should not call its what?

I don't understand the question. Another one we got wrong. (I
don't think either of us is going to get the job:).)

[...]
The difference is in the time they are initialised, and their
scope.
Any variable declared/defined at the namespace scope is
_glogal_. And it has static storage duration, which makes it
static.

The word "static" in C++ has a lot of different meanings. If
he's refering to the keyword, declaring a global variable
"static" means that it has internal linkage, rather than
external. Declaring a local variable "static" means that it has
static lifetime, rather than automatic. All global variables
have static lifetime (even if they're not "static"), and local
variables never have linkage.

And now that everybody's completely confused... :) (And I
forgot: "static" means that it's not on the stack, regardless of
where it appears. Even on a function.)

Seriously, I'd never ask a question about static without
specifying what I meant by it: the keyword, or lifetime.
There are two: sequencial and associative.

There are three: sequential, associative and unordered
associative. At least in C++0x (which, given the current date,
should be relevant real soon now).

Hmmm. It's true that the word "type" also has a very specific
meaning in the standard (and all of the STL containers are
templates, i.e. have a generic type). But I'd say that the
wording of the question makes it clear that the more general
meaning is meant here (which means that your answer was
correct).
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.

Again: does he mean in standardese, or in everyday use. In the
standard a polymorphic class is one that has one or more virtual
functions. Regardless of how you use it. In more general use
(OO design, etc.), one might not consider private bases as an
example of polymorphism.

In this regard, I'd probably ask about the LSP. If I wanted
something more C++ specific: why and when would you declare a
destructor virtual?
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.

I don't agree. A memory leak is the result of not freeing
dynamic memory that you don't need any more. Just having the
information about it isn't any good if you don't use it. Even
if the application is using garbage collection, for example, you
must ensure that you don't keep pointers which you don't use.
Those are not C++ terms.

And I've never heard of delay().
I don't know what a "fake pointer" is.

Me neither.
What's so funny about those?
That is not a complete sentence in English. The difference
_between_ a function and a member function exists and it's not
funny.
No such thing as "virtual class", but there is a "virtual base
class" -- read up on those.

There's also an abstract class, and in most cases, asking
something about them might be a good idea. (E.g. what is an
abstract class, and when would you use one?)
Friend class -- open your C++ book and read.
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.

They're two different languages?
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.

Again: is he referring to the keyword, or the general concept.
When I learned C, I learned that struct tags were in a
different namespace than other symbols. Which certainly has
nothing to do with the C++ keyword namespace. Note that even
when talking about C++, it's frequent to say things like "names
beginning with a double underscore are in the implementation
namespace."

Anyway, if this is an example of the questions they ask in the
interview, I don't think I'd get the job. And yet, I'd
consider myself a pretty competent C++ programmer.
 
J

James Kanze

yanlinlin said:
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 think some of these questions are not so good for a job
interview. And maybe this conversation is off-topic.
No specific set of questions is good for a job interview.

No specific set of questions can make an entire job interview.
In the past, I've found a very small set of fairly simple
questions useful for eliminating the bluffers, however. If you
ask "why would you declare a destructor virtual", and the
candidate responses "what do you mean by virtual", you can stop
the interview immediately, and save a lot of time. (I actually
got this answer once. From a candidate postulating as a C++/OO
expert, with several years experience in OO design and
implementation in C++. According to his CV, at any rate.)

Beyond that, of course, you discuss. You want to know not only
his technical competences, but the way he works (will he fit in
with they way your shop runs). For that matter, it's
interesting to see what questions he asks.
 
D

dizzy

James said:
Or just use the template, period. If you call a template
function, it's going to be instantiated. If you definie a
variable with a class template type, the template is going to be
instantiated.

I was thinking going even further with this, what about using it in a
context that does not call any function or declare any variable? Such as
use as part of the expression given to the sizeof operator :)
 
J

James Kanze

I was thinking going even further with this, what about using
it in a context that does not call any function or declare any
variable? Such as use as part of the expression given to the
sizeof operator :)

That will force the instantiation of a class template, or the
declaration of a function template, but not the instantiation
of the definition of a function template.
 
L

LR

James said:
Me neither.

I don't either. And yet a google search turns up a fair number of
results for the phrase.

And I still don't know.

For one thing, it seems to be one of those phrases that people use to
mean different things in different contexts.

I think I have found at least a few.

1) Using an integral type index into an array to construct a data
structure such as a linked list or tree. The kind of thing you might do
if you're using a language that doesn't support pointers.

2) Passing a pointer to something that expects the pointer to be to a
particular type when in fact it's not. Some of what I've read seems to
imply this can be (ab)used as a form of polymorphism. I'm certain that
I didn't understand this.

3) An invalid pointer, perhaps NULL, or at least one that doesn't point
to the data that the user expected it to point to. Seems to get used to
prevent certain kinds of malicious behavior.

Thinking about it, smart pointer, is a pretty broad term too.

And it's not clear to me that the terms are mutually exclusive.

If anyone can clarify the term "fake pointer" I'd like to hear it.
Anyway, if this is an example of the questions they ask in the
interview, I don't think I'd get the job. And yet, I'd
consider myself a pretty competent C++ programmer.

I don't understand what the intent of the interview questions in this
thread is.

LR
 
B

Bo Persson

James said:
Yes, what happens to them? Another question to which I don't
know the answer.

I guess the expected answer is: "Nothing, the functions are not
copied".


Did I get the job?


Bo Persson
 
V

Victor Bazarov

Bo said:
I guess the expected answer is: "Nothing, the functions are not
copied".

Is it a question you might ask somebody when you interview them?

I've not interviewed an entry-level person in years. Perhaps it is
important to validate their understanding of the C++ memory model
along with some areas of the language pertinent to your specific
development practices. For example, since I deal with performance
at least part time in my job, questions about passing by value vs
passing by a const ref would come up if I were to interview smbd.
Did I get the job?

<g> Not yet. We might have more questions. Stand by.

V
 
L

LR

James said:
James Kanze wrote:
[...]
Anyway, if this is an example of the questions they ask in the
interview, I don't think I'd get the job. And yet, I'd
consider myself a pretty competent C++ programmer.
I don't understand what the intent of the interview questions
in this thread is.

To weed out people like Victor and myself?

Heh heh.

In that case, what do the questions imply about the sort of person an
interviewer who uses them is trying to find?

Arnuld, here's some free, probably OT, advice. It's worth every penny
you paid for it.

Try to find someone who was recently hired for the kind of position you
are seeking and ask them what kinds of questions they were asked. If
you can find two people, or three, even better.

Try to find someone you can practice answering questions in front of.
If they're C++ programmers that would be nice. If they've interviewed
people that would be very good too, even if they're not programmers.

Read this article,
http://www.joelonsoftware.com/articles/GuerrillaInterviewing3.html

Best of luck.

LR
 
J

James Kanze

James said:
James Kanze wrote:
[...]
Anyway, if this is an example of the questions they ask in the
interview, I don't think I'd get the job. And yet, I'd
consider myself a pretty competent C++ programmer.
I don't understand what the intent of the interview questions
in this thread is.
To weed out people like Victor and myself?
In that case, what do the questions imply about the sort of
person an interviewer who uses them is trying to find?

Well, I find them very useful for what they tell me about the
company who's interviewing me:). Like, for example, that I
probably wouldn't want to work there anyway.
 
D

dave_mikesell

James Kanze wrote:
[...]
Anyway, if this is an example of the questions they ask in the
interview, I don't think I'd get the job. And yet, I'd
consider myself a pretty competent C++ programmer.
I don't understand what the intent of the interview questions
in this thread is.

To weed out people like Victor and myself?

This might be the first time in my Usenet history that I literally
LOL'd.
 
D

dizzy

James said:
That will force the instantiation of a class template, or the
declaration of a function template, but not the instantiation
of the definition of a function template.

But would answer the original question of "How can you force instantiation
of a Template?" :)

PS: I love to poke interviewers with such things if they ask questions like
that
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top