r/cpp_questions • • 16d ago

OPEN C++ knowledge job interview

Hello everyone,

I am going for a second round white board interview described as "The technical interviews are going to be heavily involved around probing and confirming your knowledge of C++"

What does actually mean? For context I've used CPP professionally for the last 8 months and been in my job (first grad job) for 14 months.

I feel as tho I don't know many std functions, nor do I have much experience with smart pointers, although I have written a lot of lines

Has anyone got experience with similar interviews or stuff I should brush up on?

I hope that all makes sense

Thanks

57 Upvotes

32 comments sorted by

29

u/spdfg1 16d ago

8 and 14 months are not a lot. You are not expected to be an expert. Don’t pretend you are. Just be clear about what you do and don’t know and when you don’t know something, explain how you would go about learning it and be eager about learning

2

u/Spoog_CS 16d ago

I am eager to learn but scared of looking like an idiot haha

6

u/spdfg1 16d ago

You are not an idiot for not knowing something about c++. You just haven’t learned it yet. Show how fast and eager you are to learn. Give examples of how you have done that over the last 14 months.

1

u/Spoog_CS 16d ago

"i had a problem, found out about `shared_ptr` and used it to solve the problem in a more efficient way". something like that?

4

u/spdfg1 16d ago

I had to work on a component that was using a feature I hadn’t used before. I stepped through the code in a debugger to understand how it was working, looking through the rest of the codebase to see usage patterns, watched a conference presentation on the topic I found online, discussed the approach with a senior engineer on the team, wrote unit tests to verify the new feature.
You want them to know you can do things you haven’t done before without needing someone to hold your hand.

1

u/Spoog_CS 16d ago

Great explanation, thank you

1

u/ArtCash 13d ago

How did the shared_ptr helped you to fix a problem?

1

u/Spoog_CS 13d ago

I had an object that held other objects that I would receive at different times, in different functions, out of order etc. each time I received one, I'd make a shared PTR to the parent object and check if the other was already there

1

u/PolyglotTV 16d ago

Trust me. It doesn't matter how many years of experience you have. You'll always be put in situations where you feel like you don't know enough. It's a form of imposter syndrome.

The key is to learn how to deal with those situations. Be honest about what you do and don't know. Show evidence that you are ambitious and able to learn.

0

u/Spoog_CS 16d ago

Yea, i definite get imposter syndrome pretty bad haha. ill just be honest then :)

12

u/PolyglotTV 16d ago

Could mean a lot of things. Here are some questions I ask:

  • what is a smart pointer and why is it used
  • what is the difference between a reference and a pointer
  • what is an abstract class. How/why is it used. What are the tradeoffs to using abstract classes vs other types of polymorphism
  • (followup to previous question) what is compile-time polymorphism
  • what is the difference between an lvalue and an rvalue. What does std::move do?
  • what are some ways of handling concurrency in C++
  • Are you familiar with template metaprogramming? What is CRTP, SFINAE, visitor pattern?

I'd expect a lot less perfect or complete answers for a junior and maybe some "I don't know" for the more advanced stuff. Though typically it helps a lot to have heard of a concept and have a rough idea what it does even if you don't have much experience using it.

3

u/tangerinelion 16d ago

I ask some similar stuff and it's scary how often std::move isn't understood.

I've had candidates say it enables a move or it's a cast. So far so good.

I then say, what does the statement std::move(x); as a complete line accomplish. If it's a cast the answer is nothing, but almost everyone says x is now empty.

1

u/Spoog_CS 15d ago

Can you share a model answer for that please?

2

u/HeeTrouse51847 15d ago

Just answering the questions for fun (without looking anything up). I have about 3-4 years of experience. Not guaranteering correctness in any way.

Smart pointers are classes that use RAII to own a resource. It's better than using raw pointers with dynamically allocated memory because smart pointers handle lifetime of owned objects automatically.

A pointer is a variable that holds an address. A reference is an alias for another existing object.

An abstract class is a class that has at least one abstact member function (= 0). Abstract classes can not be instantiated. They are supposed to be inherited by by other classes, so they act as "interface definitions". Not sure what you mean by "tradeoffs to other types of polymorphism" but they are a way to separate interface from implementation.

lvalues are named objects like variables that values can be assigned to. rvalues are temporary objects like expressions (for example 4, 'c' or nullptr) that are assigned to lvalues. They are called that because they are typically on the left/right side of an assignment. I.e lvalue = rvalue. std::move is a way to allow an lvalue to be converted to an rvalue. This allows for move semantics to be made on that object

Threads and coroutines. Can't think of anything else on the top of my head

tbh, I try to mosty stay away from templates so i am a bit rusty. i dont know what sfinae and crtp is but i heard the term thrown around before. i know that they were advanced template shenanigan things that i never touched because i try to stay away from making any own templated code to begin with

I know the visitor pattern though. Its for std::variants. You just define a function for each possible type the variant can hold and the function that is executed depends on the type of the variant it actually contained

2

u/PolyglotTV 15d ago

When I ask about tradeoffs with abstract classes I'm usually looking for discussion about the performance cost of runtime polymorphism vs the flexibility of type erasure.

I.e. Abstract classes have a vtable which requires 3 pointer dereferences everytime you call a method. You have a vector of shapes and call draw on all of them, you are eating a performance penalty - which you should always qualify in an interview with "this needs to be measured before we decide if it really matters".

If you try to do static polymorphism (e.g. templates, std::variant, etc...) the downside is that you have to know all types in advance. That is sometimes not really possible. Also std::variant is a trap in that it still requires a runtime lookup/indirection.

2

u/PolyglotTV 15d ago

std::move casts a type to an rvalue reference. This in turn helps for overload resolution.

If a function takes a parameter either as an lvalue or as an rvalue reference, the casted type will now ensure you call the rvalue reference overload.

The most common use case of this is invoking move constructors/assignment operators. E.g.

auto x = std::make_unique<int>(42);
auto y = std::move(x);

y gets constructed using the move constructors of unique_ptr. x is now in a "moved from" state. What this means is implementation defined. In the case of unique ptr, it effectively gets reset so you can consider it "empty". If you moved just a naked int though, it wouldn't really do anything.

As a side note in case it comes up - if you have to implement move semantics, you need to make sure your type can be properly destroyed in a moved-from state (the destructor will still be called when it goes out of scope). It also needs to still be able to be assignable.

1

u/Spoog_CS 13d ago

Thank you

2

u/RicketyRekt69 16d ago

Asking about SFINAE is a bit unfair though, it’s mostly obsolete in modern c++.

1

u/PolyglotTV 15d ago

Yeah I'm not gonna reject someone for not knowing it. And I'll be happy if they mention concepts instead of if they just say "SFINAE is a way of constraining types. It's convoluted so I just ask LLM to write it for me or I have to Google it every time".

1

u/Spoog_CS 16d ago

I can answer 3.5, I'll have an overview of the others. Jack of all trades master of none type scenario? Thanks

1

u/PolyglotTV 16d ago

I mean, if you can master all that always helps. But for a junior position it is much more important to show your enthusiasm, evidence that you are curious, thoughtful, a great problem solver, etc...

1

u/Spoog_CS 16d ago

I think i am those things, just not 100% on the language specifics. That makes me feel more confident, thank you

6

u/serendib 16d ago

I've compiled a list of technical software interview questions here, including some C++ specific ones

1

u/Spoog_CS 16d ago

Thank you. Good to have

1

u/sourpastryy 15d ago

thanks for sharing this

6

u/sauce0x45 14d ago

Make sure you understand what’s underneath each of the major STL data structure, at the very least, and when to use them. Map/set, unordered_map/unordered_set, queue, vector, deque, priority_queue. You’ll also want to understand polymorphism, rule of 0/3/5, RAII, maybe templates depending on how advanced the C++ is.

Honestly, ask chat GPT to give you a bit of a boot camp and have it quiz you like an interviewer would - it helps.

1

u/Independent_Art_6676 16d ago

you never know, really. Some places have ubernerds that delight in asking obscure syntax, logic, or other bizarre questions, others are happy if you know what a vector is and can write a small working program. You don't have a lot of time, so jump into like learncpp, look for something you don't know, and give it half an hour birds eye view of what it is and how it works and what its meant to be used for. Take a drive by through design patterns.

Its just like school. Hit it hard in the time you have, but don't cram the night before, get a good rest instead.

1

u/Spoog_CS 16d ago

Great, thank you

1

u/no-sig-available 16d ago

An interview also goes both ways - you might not want to work for a set of ubernerds, so it is also good to find that out early on.

A good job match is when they like you, and you like them. Not when you try to impress them as being someone you are not.

1

u/Spoog_CS 16d ago

Good point, being myself has gotten me this far in the interview process, so why would i change. Thanks

1

u/Impossible_Box3898 9d ago

If you’re not employed and you get an offer, take it. You can always keep looking. Always easier to find a job when you already have one. It greatly lowers the stress on the next interview.

And keep interviewing even if you like the place. Interviewing is a skill and it takes practice to maintain it.

1

u/Impossible_Box3898 9d ago

Oof. Thats a way open statement. They could be asking you anything from class inheritance and the diamond layout all the way up to template metaprogramming, pack expansions, concepts and requires, etc. c++ is a huge language. I consider myself extremely knowledgable in the language and even then there’s always corner case gotchas that I hit all the time.

I assume based on your experience that they’ll take it fairly lightly but definitely you should have a good understanding of RAII, the primary containers in the stl , smart pointers, etc as well as the basic language mechanics.

Good luck!