Author Topic: C++ interview questions that do not suck  (Read 33138 times)

0 Members and 1 Guest are viewing this topic.

Offline Galaxyrise

  • Frequent Contributor
  • **
  • Posts: 531
  • Country: us
Re: C++ interview questions that do not suck
« Reply #25 on: May 08, 2014, 04:01:58 am »
Not an interview question but a quiz. A C/C++ program has two adjacent lexical tokens (on the same line). Inserting a space character between them changes the semantic of the program. How come?
The first that came to mind is the one that's "fixed" in C++ 0x11, but then I'm not sure that qualifies as a "semantic" change.  Then I can think of one that's precedence-based.
I am but an egg
 

Offline Galaxyrise

  • Frequent Contributor
  • **
  • Posts: 531
  • Country: us
Re: C++ interview questions that do not suck
« Reply #26 on: May 08, 2014, 04:16:57 am »
Can the numerical value of a pointer change after an assignment?
I don't understand this phrasing.

Quote
P1 == P2 but ((void *) P1) != (void *) P2)

If so, why?
I thought this was cute!  I'm not sure if it's a good face-to-face interview question; if the candidate doesn't get it immediately then I'm not sure there's a lot to talk about and you risk the stress of the situation shutting them down.

I got the answer you're looking for almost instantly.  But later I realized that the code snippet above can be explained by a second, very different (and fairly C++) answer.  Very nice :) 

Quote
You're debugging some code, and you notice that an array of yours gets partially trashed after stepping through some trivial code that shouldn't or can't effect that array.

What might be happening?  Describe how you'd continue to isolate the problem.
  I second this one.  I love discussing debugging during an interview, especially for more senior people

I am but an egg
 

Offline JuiceKing

  • Regular Contributor
  • *
  • Posts: 233
  • Country: us
Re: C++ interview questions that do not suck
« Reply #27 on: May 08, 2014, 04:23:33 am »
It's been a while since I interviewed C++ software engineers. A great question back when I did was, "What do you think of the C++ ampersand operator?"

Possible answers:

1. I don't know
2. Um, it's great?
3. It sucks

We liked #3 because it showed that we were interviewing someone with real team programming experience.

 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: C++ interview questions that do not suck
« Reply #28 on: May 08, 2014, 05:17:39 am »
Quote
"What do you think of the C++ ampersand operator?"

Possible answers:

I'd hope for "Which one?", I think.  Binary "&" and "&&" should be fine, right?   Unary "address of" is just like C, and doesn't seem too awful.  But the whole "passed-by-reference argument" makes me really nervous (do you still consider that an "operator"?)  I mean: I actually managed to redefine 0, once, in a fortran program...
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: C++ interview questions that do not suck
« Reply #29 on: May 08, 2014, 05:21:12 am »
It's been a while since I interviewed C++ software engineers. A great question back when I did was, "What do you think of the C++ ampersand operator?"

Possible answers:

1. I don't know
2. Um, it's great?
3. It sucks

We liked #3 because it showed that we were interviewing someone with real team programming experience.
Um, maybe the rest of your team wasn't really comfortable with C++? ... "const T &x" is a crucial concept to master.
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 9939
  • Country: nz
Re: C++ interview questions that do not suck
« Reply #30 on: May 08, 2014, 06:22:07 am »
Ask them to write out any bit of code or function which they think is interesting, or maybe just something they have recently written which is fresh in their mind.
Then get them to explain how it all works.

Usually that's less stressful. As opposed to giving them a random task and asking for a function to solve it.
You want to see if they can A) write code  B) Understand it
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: C++ interview questions that do not suck
« Reply #31 on: May 08, 2014, 06:42:08 am »
I'm surprised to see so many questions focusing on the syntax and semantics of the language, which is stuff which I'd have thought would be easy enough to pick up on the job as and when (and if) it becomes relevant.

If you're hiring someone to write code, presumably you're hiring them to write code that will run on a particular platform and will ultimately solve some problem. Why not ask questions that probe their understanding of the context in which their code will be running? Things like:

- Knowledge of the OS
- techniques to ensure their code 'plays nice' with other tasks, and doesn't break them
- reasons why code which works in the debugger might fail in a production build, and vice versa
etc.

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: C++ interview questions that do not suck
« Reply #32 on: May 08, 2014, 07:13:08 am »
so, I know how to speak and think, so maybe I could just work as a German translator, well I'm fluent in 3 languages  other than German, and I can think in either. Actually i dream in all of them and my wife freaks out when I speak in tongues!  :-DD

So I should get a job because I will learn German while at the job, right?

Nah, you gotta know the language they work with. Being bright is a plus but unless the job is for an internship, there is no way I'll hire you.

You gotta know the actual programming language the job is for. I don't mind if we have to train you on our ways of doing things (toolchains etc) but you better know the programming language you are going to work with. Actually you better have a good grasp on concurrency and asynchronous processing.

And you better keep up with changes in programming. Think of it as you never left college.

 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: C++ interview questions that do not suck
« Reply #33 on: May 08, 2014, 07:24:37 am »
Not an interview question but a quiz. A C/C++ program has two adjacent lexical tokens (on the same line). Inserting a space character between them changes the semantic of the program. How come?
The first that came to mind is the one that's "fixed" in C++ 0x11, but then I'm not sure that qualifies as a "semantic" change.  Then I can think of one that's precedence-based.

The answer I know is

#define A(x)
  vs
#define A (x)

The first defines a macro with one argument that is expanded to nothing. The second defines a zero argument macro that is expanded to '(x)'.

(Not recommended as interview question, it's too much of an aah-moment question).
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8269
Re: C++ interview questions that do not suck
« Reply #34 on: May 08, 2014, 10:27:59 am »
Here you have an UML diagram.
Give the classes.h file.

Of the UML diagram of class A, write the constructor and destructor.
Did you miss the "not" in the title? :P

Not an interview question but a quiz. A C/C++ program has two adjacent lexical tokens (on the same line). Inserting a space character between them changes the semantic of the program. How come?
Greedy parsing? Here's an example:
Code: [Select]
x = a+++b; /* parsed as a++ + b, i.e. a is incremented */
x = a+ ++b; /* parsed as a+ ++b, i.e. b is incremented */
 

Offline JuiceKing

  • Regular Contributor
  • *
  • Posts: 233
  • Country: us
Re: C++ interview questions that do not suck
« Reply #35 on: May 08, 2014, 03:25:12 pm »
Quote
"What do you think of the C++ ampersand operator?"

Possible answers:

I'd hope for "Which one?", I think.  Binary "&" and "&&" should be fine, right?   Unary "address of" is just like C, and doesn't seem too awful.  But the whole "passed-by-reference argument" makes me really nervous (do you still consider that an "operator"?)  I mean: I actually managed to redefine 0, once, in a fortran program...

As you guessed, I mean the "passed-by-reference argument." In C, you could be certain that a called function would leave your local variables alone, unless you passed pointers to them. In C++, you never really know.
 

Offline JuiceKing

  • Regular Contributor
  • *
  • Posts: 233
  • Country: us
Re: C++ interview questions that do not suck
« Reply #36 on: May 08, 2014, 03:28:20 pm »
It's been a while since I interviewed C++ software engineers. A great question back when I did was, "What do you think of the C++ ampersand operator?"

Possible answers:

1. I don't know
2. Um, it's great?
3. It sucks

We liked #3 because it showed that we were interviewing someone with real team programming experience.
Um, maybe the rest of your team wasn't really comfortable with C++? ... "const T &x" is a crucial concept to master.

That depends on best practices of the writer of the called function, doesn't it? I like being about to step over a function in a debugger and not having to worry about local variables being messed up.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: C++ interview questions that do not suck
« Reply #37 on: May 08, 2014, 04:56:01 pm »
In C, you could be certain that a called function would leave your local variables alone, unless you passed pointers to them. In C++, you never really know.
On the flip side, C++ lets you return useful data in an "output" argument, and a boolean from the call itself to say whether the call succeeded. In C, you usually return a possibly-NULL pointer which you have to check.

Another great thing about references (aka the ampersand operator) is that they can't be NULL--at least not without having to fool the compiler explicitly. So if you write a C++ API that passes something by reference, that's effectively saying you *must* have an actual data object, and thus you never even have to check the argument for NULL.

 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: C++ interview questions that do not suck
« Reply #38 on: May 08, 2014, 05:37:02 pm »
I absolutely agree, the language itself is a means to an end. It's an important tool, for sure, but focusing on the language itself ignores the much more important fact that the software is a part of a wider system.

It's the software engineer's role to make that system live and breathe, and that means the most important skill the engineer can have is the ability to understand how the system works. That's not something that can be googled as necessary, or copied from existing code fragments.

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: C++ interview questions that do not suck
« Reply #39 on: May 08, 2014, 05:43:19 pm »
Best question: Who created C++
Best answer:  Barney Shoestrap.
bjarne hoestsiroop (in dutch). hoestsiroop = cough syrup ..
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline madshaman

  • Frequent Contributor
  • **
  • Posts: 698
  • Country: ca
  • ego trans insani
Re: C++ interview questions that do not suck
« Reply #40 on: May 08, 2014, 05:58:15 pm »
Best question: Who created C++
Best answer:  Barney Shoestrap.
bjarne hoestsiroop (in dutch). hoestsiroop = cough syrup ..

lolololol
To be responsible, but never to let fear stop the imagination.
 

Offline vvanders

  • Regular Contributor
  • *
  • Posts: 124
Re: C++ interview questions that do not suck
« Reply #41 on: May 09, 2014, 02:24:41 am »
I would never hire the best C++ programmer not even for a C++ job. I would hire a very good programmer with good C++ skills. C++ is the best proof of thousands of way to kill evolution. I am programming C++ since it came into being. It's limitation caused libraries with tons of megabyte of code, because of the absurd C++ philosophy. Stroustrap himself is a bad evangelist who was good only in succeeding.  Electronics evolved thousands of times more in all this time. Electronics engineers seem to have more imagination and creativity as their imagination and creativity is stimulated versus the creativity and imagination of C++ programmers that is just killed. I discovered some love for mcu-s, but I had to acknowledge that C++ arrived here as well. That is not yet as bad... But when the bloat will arrive... I am telling you the bloat will arrive but mcu's will not do much more ;) :-DD  :-DD

So C++ interview question tips: distribute your questions: 2% C++ (this means no question ;) ) the rest of the 98 percent equially distributed to see how smart the guy is and how creative he is. A hyper intelligent guy will learn for you C++ in two weeks! An idiot C++ programmer will never ever be able to cut a potato in two equal pieces  :-DD  :-DD  :-DD

That's being a bit harsh on the language, the best C++ programmers know when to avoid features or omit them entirely. I very much doubt that someone could learn C++ in two weeks, there's quite a few concepts like templates, value type semantics, placement new, deterministic destruction and many others that take a while to understand in C++.

Yes the language is complex but that allows for a much greater expression and control. And as always, using the right language for the job. I regularly switch between Python, Javascript, C#, C++ and Java depending on the task, domain space and technical requirements.

This is a great talk that covers why C++ is still relevant today and where it should fit into your toolbox(also some great performance stuff that most CS people aren't aware of):
http://channel9.msdn.com/Events/Build/2014/2-661

As for EE vs SE, I won't even go there :)
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: C++ interview questions that do not suck
« Reply #42 on: May 09, 2014, 10:04:03 am »
This is why I'd choose to concentrate on how well the candidate understands concepts and systems, rather than syntax and semantics. If a newly hired engineer spends a few months learning more efficient, elegant, or just plain fashionable ways to write code, then that's OK.

If, however, that time is spent writing code which contains race conditions, poorly handled interrupts and buffers which are liable to overflow, then that's a problem.

Offline grumpydoc

  • Super Contributor
  • ***
  • Posts: 2905
  • Country: gb
Re: C++ interview questions that do not suck
« Reply #43 on: May 09, 2014, 12:48:59 pm »
One question I've used where people claim to have good C++ (or C) skills is "tell me what you do not like about C++, or how it could be improved".

 

Offline madshaman

  • Frequent Contributor
  • **
  • Posts: 698
  • Country: ca
  • ego trans insani
Re: C++ interview questions that do not suck
« Reply #44 on: May 09, 2014, 02:55:29 pm »
Someone mentioned that it would be really hard to learn C++ in two weeks because of its complexity.  I disagree somewhat, I think that's plenty of time to become effective at a new language.  C++ doesn't really have any unique semantics or concepts, that two weeks would really be spent learning syntax, some standard libraries, a handful of gotchas, and maybe becoming familiar with how the average compiler emits the target object code.

The programmer doesn't have to become a C++ geek either, a handy assortment of references will suffice until some things are committed to memory.

It's not black and white because some programmers, especially those without low-level experience or experience in many types of languages, might have a much longer learning curve and can't possibly hit the ground running.

Candidates run the gamut from those with a Master's degree who can't do anything useful other than get good marks to high-school drop-outs who can run circles around the former.

This thread seems to be turning into "how to hire good coders", and I'd say the best way is to get your best coder(s) to interview the final cut in person.  Anyone worth their salt, whatever methods they use can easily determine someone's skill.
To be responsible, but never to let fear stop the imagination.
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1997
  • Country: us
    • netstuff
Re: C++ interview questions that do not suck
« Reply #45 on: May 09, 2014, 03:46:46 pm »
Asking someone to write pseudocode in an interview is not ideal but okay I suppose. You have to keep in mind that some people are not good at jumping into new things quickly during a short interview, but perfectly competent programmers. Not everyone works the same way.

Interviews are overrated anyway. You just have to accept that you won't really know how good somoene is until they have been working for you for a few weeks, which is what the probation period is for.

bingo!

this is a hot button for me.  I've been writing software since I was in my early teens and I'm early 50's now.  I have decades of programming under my belt and I've written probably over a million lines of code by now.

yet, I fail horribly when asked to 'perform, live' in an interview.  I just cannot do it well!  and few employers seem to understand that; and almost no engineers I meet during the interviews understand it, either.

I think some of it is age.  when I was in my 20's, I could code 'in front of people' just fine, but now, I'm not wired that way (lol) and find it difficult to write code on a board or even on paper, while under the magnifying glass.  its also not my style anymore, I will usually consult online examples, grab some code, modify it and adapt it.  we used to use books for ref, but now we use online examples and I feel almost naked without being online and having a real text editor (not paper or whiteboard) to do the program entry.

my programming skills are more than enough to get the job done, and my resume should prove that to employers, but time and time again, they insist on these stupid coding tests and they put all their faith into it.

its rare to find a company that cuts thru that BS and its refreshing to run into them, when I do.  maybe 1 out of 50 don't do the stupid tests.  maybe even 1 out of 100, these days.  its really a tiny minority.

it also cracks me up with I interview with people very much younger than me.  more times than I can remember, the person at the other end of the table has been alive less time than I've had work experience, and yet they're passing judgement over me based  on 15 minutes of 'stand up' coding on a whiteboard.

the whole thing is farked up.  not everyone works that way.  I don't.  and yet, companies won't change the way they interview.  they don't hire folks like me and they are missing out on good people, to be sure.

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1997
  • Country: us
    • netstuff
Re: C++ interview questions that do not suck
« Reply #46 on: May 09, 2014, 03:50:29 pm »
For EEs you could try "how suitable for embedded development is C++?"

data point: I had an interview at samsung (corp, san jose) yesterday for their SAS storage division.  the enterprise ssd stuff.  all their code ON EMBEDDED CONTROLLERS is c++.  I was very surprised.  I would have guessed C but I guess some 'new kids' thought c++ would be teh new hotness and so they use it.

speed matters and memory matters but they are using c++ on sas controllers?

boggle....


Offline madshaman

  • Frequent Contributor
  • **
  • Posts: 698
  • Country: ca
  • ego trans insani
Re: C++ interview questions that do not suck
« Reply #47 on: May 09, 2014, 03:58:37 pm »
the whole thing is farked up.  not everyone works that way.  I don't.  and yet, companies won't change the way they interview.  they don't hire folks like me and they are missing out on good people, to be sure.

So, start your own software company, then your success will be directly related to how good you are.  You can eventually hire the good people these other companies are passing up.

You can't expect a company to change itself for you.  Behind that company are investors and founders who did what was required to form a company that generates enough money to be able to give people like yourself a stable and predictable income; they've actually earned the right to run themselves however they see fit.

You have a better way, so do the same thing the founders of those companies did (including taking on all the risk and hard work it takes to do that) and then your company can have whatever hiring policies you choose.
To be responsible, but never to let fear stop the imagination.
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1997
  • Country: us
    • netstuff
Re: C++ interview questions that do not suck
« Reply #48 on: May 09, 2014, 04:03:50 pm »
starting a company usually ends in failure, given the stats.  I can't afford that right now.  few people can.

the rest of what you posted is neither here nor there.  companies need programmers but they are going about it all wrong and the state of software quality in the industry is PROOF that they are doing it all wrong.

been there, seen 'production' code by so-called wiz kids and its total BS.

my point is that their process often rejects the people they should actually be hiring.  and the ones who can memorize a linked list or tree delete are the ones that are NOT the most creative, but just good at memorization.  those are the worst programmers, generally, as they run out of steam quite fast when its not something they studied and memorized, previously.

the only way to be sure is to try someone out.  in the US, the new culture is to hire 'contractors' for trying them out and then make them 'perm' 3/6/12 months later if it works out.  you don't need to spend a lot of time testing contractors during an interview; the JOB is the test and it will be obvious in short time if they can do the work or not.  and you'll see them in real world conditions, not synthetic ones.

Offline madshaman

  • Frequent Contributor
  • **
  • Posts: 698
  • Country: ca
  • ego trans insani
Re: C++ interview questions that do not suck
« Reply #49 on: May 09, 2014, 04:18:26 pm »

starting a company usually ends in failure, given the stats.  I can't afford that right now.  few people can.

Well then lucky for you *others* took that risk and made sacrifices so that they can provide *you* with a nice stable job, group benefits etc.

As far as "I can't afford that", bullshit, and I'm calling you on it; there are a number of billionaires, who started with much less than you, who would disagree with you there.

You're an SE, what is your overhead?  A computer?

Have you tried?  If you did, didn't you learn anything so the next time you'll have a better chance?

Honestly, I think it's easier to say "it's not possible because: a, b, c, d, e...." than risk failure.

I'm being pretty critical of you, but it's not to derogate you.  I could be wrong but I'm worried you're learning to be helpless, it doesn't sound from your experience like you are helpless.

Quote
the rest of what you posted is neither here nor there.  companies need programmers but they are going about it all wrong and the state of software quality in the industry is PROOF that they are doing it all wrong.

I respect your opinion, but if they're "doing it all wrong" and there's proof, isn't that an opportunity?  I'd be very pleased if someone came to me and said "you're doing it all wrong, I can show you how to do it right" and was able to deliver; I'd probably give them money to keep making me more money.

If you think you're right (and I'm positive your opinions aren't 100% groundless), then prove it; I'll be first in line to support you and sing your praises.
To be responsible, but never to let fear stop the imagination.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf