lefticus / cpp_weekly

The official C++ Weekly Repository. Code samples and notes of future / past episodes will land here at various times. PR's will be accepted in some cases.
The Unlicense
706 stars 26 forks source link

Preparing for C++ interviews #100

Closed SamiraMHosseini closed 11 months ago

SamiraMHosseini commented 2 years ago

I haven't been able to find good and reliable resources for C++ interview questions and I am lost and don't know what to study and what topics matter most!

lefticus commented 2 years ago

Twitter thread: https://twitter.com/lefticus/status/1554844035751165952

Ideas:

lefticus commented 2 years ago
lefticus commented 2 years ago

See this terrible example: https://twitter.com/IgnitionWeb/status/1554865524500320260

marzer commented 2 years ago

If you think you're a 4/10, you're probably a 2/10. If you think you're an 8/10, you're probably a 9/10

~Isn't this partly backwards?~

Wait, never mind. Just double-checked the wiki article and this makes sense.

CorrodedCoder commented 2 years ago

"Demonstrate curiosity" as this seems to be one constant I've gleaned primarily by being the interviewer, but also being the interviewee. If you don't know the answer to something then don't be afraid to acknowledge that up front (it's usually not hard to tell), but equally if you think you might know something related then ask them if they'd like you to speculate. Later on in an interview, I typically ask a question that has no right/perfect answer that requires the candidate to speculate on something that could have any number of possible outcomes depending on what the compiler does, time, threading, and it's ideally a very interactive discussion. The purpose is to see how well the candidate collaborates on something they aren't trivially able to answer. The best outcome is that they get really interested in the problem & discussion and forget they're in an interview at all and this gives me a feel for what it will be likely working with them. The worst outcome is a refusal to engage at all. I'm not saying this is perfect and it certainly has to be done sensitively (and once they are relaxed) but I have found it to be useful to me.

lefticus commented 2 years ago
Paiusco commented 2 years ago

A few that I remember hearing/using:

Then we could show some code for review or do a quick "pair programming session" with a quick assignment.

CorrodedCoder commented 2 years ago

Assuming a candidate for something beyond a graduate role, a very key indicator for me is some understanding of resource management followed by being able to write exception neutral code. In my example I tend to combine them both to something like:

int * data=new int[100];
do_something(data, 100);
delete data;

The sorts of things I am aiming to tease out are:

  1. What happens if an exception is thrown in do_something? I'm looking for the most basic risk of a memory leak.
  2. How would you improve the situation? Use std::vector is an answer which tells me a lot about the sort of code they are used to. Use int data[100]; is great too, but I then change the question so the size is variable. Answers involving catch and release aren't without value, but they are a bit earlier on their C++ journey.
  3. Check for data being NULL is an interesting discussion and awareness around the possibility of "new" throwing is another good sign, but I am not too fussed about someone knowing the correct behaviour (mostly because "it depends", or at least it used to).
  4. Recognition of the missing [] on the"delete" line and the potential consequences depending on POD vs object can be another interesting indicator of depth of understanding, although a newer C++ programmer may have been in the lucky position never to have issued an explicit "delete", which would only arouse envy in me.

The actual choice for the"do_nothing" may vary between some inline code that actually demonstrates a throw. As interviews are quite artificial situations it can be more helpful to show something concrete, but at the risk of making the question more involved.

lefticus commented 2 years ago
lefticus commented 11 months ago

Closing as merged with #194 that episode is not C++ specific, but I think it all comes around.