10 questions to determine familiarity with C++



  • My company is recruiting, and I was asked to write up 10 quick questions (multiple choice or just a couple sentences for the answer, should not take more than 10-15 minutes total) to filter candidates. I'm not going to actually have any contact with the candidates. As it was explained, it should be difficult enough to filter up to a junior level, meaning juniors should not be able to answer everything. And maybe not focus on obscure syntax too much.

    I've never had to interview anyone before, so I'm having some trouble deciding what to include. Some ideas I have (correct answer in bold) (I was asked for at least 4 answers for each multiple choice questions):

    1 - What's the difference between a struct and a class?
    a) There's no difference.
    b) Struct members are public by default.
    c) Structs can't have member functions.
    d) You can't inherit a struct from a class.

    2 - Which of the following statements about inheritance is true?
    a) Derived classes can't access the protected members of a private base class.
    b) You can pass an object of a derived class to a function taking a reference to the base class.
    c)
    d)

    3 - Which of the following is not an use of the static keyword:
    a)
    b)
    c)
    d)

    4 - Given a system with the following characteristics:
    sizeof(char) == 1, alignof(char) == 1
    sizeof(int) == 4, alignof(int) == 4
    sizeof(SomeType) == 8, alignof(SomeType) == 4
    sizeof(double) == 8, alignof(double) == 8
    What are the size and alignment of MyType

    struct MyTpe {
      char a;
      SomeType b;
      int c;
      double d;
    };
    

    a) sizeof(MyType) == 21, alignof(MyType) == 8
    b) sizeof(MyType) == 24, alignof(MyType) == 8
    c) sizeof(MyType) == 26, alignof(MyType) == 8
    d) sizeof(MyType) == 32, alignof(MyType) == 8

    Something about templates, but hard to think of a multiple choice question with them.

    My biggest issue is I don't just want to make it all be obscure trivia or pedantic dickweedery, but I don't feel the format leaves me much choice.


  • sockdevs

    @Kian

    1: B

    2: B

    3: E_NO_ANSWERS

    4: B

    5: E_NO_QUESTION

    6: E_NO_QUESTION

    7: E_NO_QUESTION

    8: E_NO_QUESTION

    9: E_NO_QUESTION

    10: E_NO_QUESTION


  • I survived the hour long Uno hand

    It has to be multiple choice? It's a lot easier to pick out the right statement among four than it is to come up with the right answer yourself. Means you have to make the questions that much harder


  • sockdevs

    in all seriousness now:

    i've honestly hated these sort of questionaires before, both as interviewee and interviewer. so my advice is simple:

    1. If the question is directly relevant to the day to day usage of your codebase, go ahead and include it, otherwise skip it. if it's not vital to the day to day they can google it, and if it is vital to the day to day they can learn it if they have the aptitude

      • For my current job i was asked if i wrote a language i havent heard of before, i answered " Not yet, give me a book and a weekend though, and i'll give it a shot"
    2. Include five programming questions exercising various aspects of programming and ask the candidate to provide solutions for three of them. Make them common problems but play with them to the point where they're not googleable.

      • For example the example question i gave to my intern this year was:

           Write me a program that reads an integer from the user and prints the numbers from one to the input number. 
           If the number to be printed is exactly divisible by seven print the word "Bert", if the number to be printed is 
           exactly divisible by eleven print "Ernie" unless the number is exactly divisible by both seven and eleven. in that
           case print the words "Rubber Duckie"
        
    3. If the candidate passes these problems bring their solutions to the interview and ask them questions about their solutions, also ask questions about the ones they did not provide solutions for, things like why they chose to answer the ones they did and omit the ones they didn't answer. stuff like that.



  • @accalia Perhaps I was not too clear: I want help / sympathy in coming up with these. Also, I'm hoping people's natural pedantry will catch any mistakes I make. I figure I spend my time here instead of working, maybe I can get you guys to do my job too.

    Also, you got 3 wrong. It's a trick question: there's nothing that is not an use of the static keyword.

    You did show that I need a better random number generator though. Mine seems to be stuck on B. Maybe I should make all the correct answers but one be B, just to mess with them.

    @Yamikuronue It doesn't have to be multiple choice, but if it's not, it should not take more than a couple of short sentences to answer it. Which is kind of a pain. Also, they're more interested in language familiarity than general programming knowledge.



  • Here's one that was a real interview question put in front of me:

    class vertex {
    public:
    float x,y,z;
    
    // snip getters and setters and red herrings
    static vertex *create()
    {
    vertex v;
    return &v;
    }
    };
    

    "Do you see anything in this code that you would change?"


  • sockdevs

    @Kian said in 10 questions to determine familiarity with C++:

    @accalia Perhaps I was not too clear

    nah. that was my failure to parse and an overactive snark module, see my later post for actual constructive advice. ;-)


  • I survived the hour long Uno hand

    @Kian said in 10 questions to determine familiarity with C++:

    It doesn't have to be multiple choice, but if it's not, it should not take more than a couple of short sentences to answer it.

    While it might be easier to write multiple choice, you'll end up with a better product using short-answer questions like "When should you use a struct, and when a class?" than you will with MCs.



  • @accalia said in 10 questions to determine familiarity with C++:

    in all seriousness now:

    i've honestly hated these sort of questionaires before, both as interviewee and interviewer. so my advice is simple:

    1. If the question is directly relevant to the day to day usage of your codebase, go ahead and include it, otherwise skip it. if it's not vital to the day to day they can google it, and if it is vital to the day to day they can learn it if they have the aptitude

      • For my current job i was asked if i wrote a language i havent heard of before, i answered " Not yet, give me a book and a weekend though, and i'll give it a shot"
    2. Include five programming questions exercising various aspects of programming and ask the candidate to provide solutions for three of them. Make them common problems but play with them to the point where they're not googleable.

      • For example the example question i gave to my intern this year was:

           Write me a program that reads an integer from the user and prints the numbers from one to the input number. 
           If the number to be printed is exactly divisible by seven print the word "Bert", if the number to be printed is 
           exactly divisible by eleven print "Ernie" unless the number is exactly divisible by both seven and eleven. in that
           case print the words "Rubber Duckie"
        
    3. If the candidate passes these problems bring their solutions to the interview and ask them questions about their solutions, also ask questions about the ones they did not provide solutions for, things like why they chose to answer the ones they did and omit the ones they didn't answer. stuff like that.

    so... fizzbuzz


  • sockdevs

    @lordofduct said in 10 questions to determine familiarity with C++:

    so... fizzbuzz

    yes, congratulations, you passed!

    it's a fizbuzz that you can't google though, so if you don't know the problem already you can't cheat. and if you know the problem by sight you're probably good enough that you can code it in your sleep.



  • @accalia said in 10 questions to determine familiarity with C++:

    i've honestly hated these sort of questionaires before, both as interviewee and interviewer.

    I feel the same way, it's part of why I'm struggling. While your advise is good, and how I'd like to structure the questionnaire, unfortunately asking them to write even simple programs or functions may require too much time given the constraints I was given. Not sure I'll be in the interviews, even. Someone else will handle that.

    @Groaner said in 10 questions to determine familiarity with C++:

    Here's one that was a real interview question put in front of me:

    One or two questions like that could work. Hide some ugly bug in a short bit of code and see how long it takes them to see it.

    @Yamikuronue said in 10 questions to determine familiarity with C++:

    you'll end up with a better product using short-answer questions like "When should you use a struct, and when a class?" than you will with MCs.

    Good point. Straight questions with a clear answer, if they find it hard then they're probably lacking experience.



  • @Kian said in 10 questions to determine familiarity with C++:

    I don't just want to make it all be obscure trivia or pedantic dickweedery

    And then you include struct alignment questions. Is that something that comes up on the job?

    Think about what you expect the candidate to do and what kind of knowledge do you expect them to need.



  • @Kian - So how I personally go about interviews, if I had to implement it as a 10 question quiz (I'm going to allow short answer questions, because some just need it)

    Part 1 - determine logical abilities (language independent)

    Your first few questions could be logics based. One of my favourites is:
    There is a deck of cards on one side of which are letters, and the other side of which are numbers. There is 1 rule:
    if a card has a vowel, the number on the other side must be an even number
    4 cards are dealt in random order/facing:

    E 4 5 L

    What fewest cards would you need to flip over to verify the rule is true?

    The nice thing about this puzzle is that the answer isn't just right or wrong. You can be right, sort of right, wrong, or way wrong. Depending on the answer you can have a nice bar to work with, like if they said E, 4 and 5, they're really close, they just flipped on unnecessary card. But they obvsly had the right idea in mind.

    Part 2 - understanding of design and problem solving

    Again, language ambiguous. Maybe even just psuedo-code.

    But have a couple questions that either make a person decide how the problem should be solved, and have some code that they should identify what it's attempting to do and why... you could easily pull something from your own library of code for this, but reformat it as psuedo-code and strip out any sensitive bits.

    Part 3 - actual language knowledge

    C++ knowledge is freaking hard to gauge in the skill range you're looking for... not sure what you're bar is.

    I wouldn't be asking inheritance problems, or basic "structs have public fields by default, classes don't" type stuff. But rather the things that trip people up.

    Big one... pointers. Time and time again, people fuck up pointers. A good pointer question might be setting up a linked list. Honestly you could integrate this into Part 2... have a type that has a 'next' pointer for setting up a linked list, and see if the person notices what the purpose of it is. I'd consider this rudimentary enough for a junior I'd want, while at the same time not be so complicated that even good programmers on a bad day might overlook into in the stress of answering a interview quiz.

    part 4 - during interview, evaluate aptitude and desire to learn

    Honestly, this is a BIG one to me.

    If a developer is not active in some community (even frivolously like hanging out here), or actively seeks out new languages, ideas, or expanding their knowledge in tangential fields... they're not worth my time.

    When I meet that programmer who knows 1 or 2 languages, and sees no point in learning others, I'm concerned. I get being masterful in only 1 or 2 languages because that's all your jobs demanded of you at that point... but have you tinkered in anything else???

    This one has wiggle room and doesn't fit on a quiz. But should definitely be brought up in an interview.



  • @Kian You should consider leaving the boldface markup off the correct answers, as it makes your test too easy.



  • This post is deleted!

  • sockdevs

    @anotherusername said in 10 questions to determine familiarity with C++:

    The answer is one (E). The only correct answer is one.

    given four cards were dealt i assume we are dealing with just the four, i would answer two cards. the E and the 5

    we need to flip E to verify that there is an even number on it to satisfy the rule, and we need to flip 5 to verify that the value on the back is NOT a vowel becasue otherwise we hava a violation of the rule.

    we don't need to flip 4 because if a vowel is on the other side the rule is obeyed and otherwise it is not violated, likewise with L because we don't care what number is on the back as we have no rule for consonants.



  • @lordofduct said in 10 questions to determine familiarity with C++:

    Your first few questions could be logics based. One of my favourites is:
    There is a deck of cards on one side of which are letters, and the other side of which are numbers. There is 1 rule:
    if a card has a vowel, the number on the other side must be an even number
    4 cards are dealt in random order/facing:

    E 4 5 L

    What fewest cards would you need to flip over to verify the rule is true?

    The entire deck, because there are no unique constraints on the contents of each card's front or back, and by the same token, there isn't a guaranteed 1:1 mapping between each letter and number, nor are there constraints on the range of possible numbers.


  • sockdevs

    @Groaner said in 10 questions to determine familiarity with C++:

    The entire deck,

    would have to be dealt if we are validating the rule for the whole deck. and in that case all odd numbers and vowels would need to be flipped to verify. even numbers and consonants need not be flipped.



  • @accalia you are correct, I forgot that you'd need to flip 5 to see if it disproved the rule by having a vowel on the other side.

    A ⇒ B
    ¬B ⇒ ¬A



  • @accalia said in 10 questions to determine familiarity with C++:

    @Groaner said in 10 questions to determine familiarity with C++:

    The entire deck,

    would have to be dealt if we are validating the rule for the whole deck. and in that case all odd numbers and vowels would need to be flipped to verify. even numbers and consonants need not be flipped.

    The rule is introduced before any mention of dealing out the cards, therefore it should be interpreted as applying to the whole deck.

    Also, there isn't just one rule. A second rule is that cards have letters on one side and numbers on the other.



  • @Groaner said in 10 questions to determine familiarity with C++:

    @lordofduct said in 10 questions to determine familiarity with C++:

    Your first few questions could be logics based. One of my favourites is:
    There is a deck of cards on one side of which are letters, and the other side of which are numbers. There is 1 rule:
    if a card has a vowel, the number on the other side must be an even number
    4 cards are dealt in random order/facing:

    E 4 5 L

    What fewest cards would you need to flip over to verify the rule is true?

    The entire deck, because there are no unique constraints on the contents of each card's front or back, and by the same token, there isn't a guaranteed 1:1 mapping between each letter and number, nor are there constraints on the range of possible numbers.

    You're validating the rule for the 4 cards dealt, not the entire deck.

    And even if you dealt the entire deck out, you wouldn't have to flip the entire deck to validate. You'd only have to flip any upward facing vowels, or upward facing odds.



  • @Groaner said in 10 questions to determine familiarity with C++:

    Also, there isn't just one rule. A second rule is that cards have letters on one side and numbers on the other.

    That wasn't a rule, it was a "given".



  • @lordofduct said in 10 questions to determine familiarity with C++:

    @Groaner said in 10 questions to determine familiarity with C++:

    @lordofduct said in 10 questions to determine familiarity with C++:

    Your first few questions could be logics based. One of my favourites is:
    There is a deck of cards on one side of which are letters, and the other side of which are numbers. There is 1 rule:
    if a card has a vowel, the number on the other side must be an even number
    4 cards are dealt in random order/facing:

    E 4 5 L

    What fewest cards would you need to flip over to verify the rule is true?

    The entire deck, because there are no unique constraints on the contents of each card's front or back, and by the same token, there isn't a guaranteed 1:1 mapping between each letter and number, nor are there constraints on the range of possible numbers.

    You're validating the rule for the 4 cards dealt

    Oh, ok.



  • @anotherusername It's impossible to ask about interview questions without this kind of pedantic dickweedery, isn't it? Sigh. At least it's not fizzbuzz this time.


  • sockdevs

    @Groaner said in 10 questions to determine familiarity with C++:

    Also, there isn't just one rule. A second rule is that cards have letters on one side and numbers on the other.

    0_1469130840310_upload-e0ceee98-0731-4e42-90e8-683095542cbe

    this is true, however we are only asked to verify the truth of one of the rules.

    as to wether we are verifying it for the deal or verifying it for the whole deck i can answer that the number of cards we must flip to verufy the rule we are asked to verify over the entire problem space is:

    N(cards showing vowels) + N(cards showing odd numbers)



  • @accalia - precisely, I'm asking you validate 1 rule... the other is a given, considered true.

    You wouldn't be able to validate the vowel=>even rule, if the letter oneside, number other side weren't a given.


  • sockdevs

    @blakeyrat said in 10 questions to determine familiarity with C++:

    At least it's not fizzbuzz this time.

    nope! instead we have RubberDucky.



  • @Maciejasjmj said in 10 questions to determine familiarity with C++:

    @Kian said in 10 questions to determine familiarity with C++:

    I don't just want to make it all be obscure trivia or pedantic dickweedery

    And then you include struct alignment questions. Is that something that comes up on the job?

    Think about what you expect the candidate to do and what kind of knowledge do you expect them to need.

    That's a good point. Should take it out. In my defense, I said I didn't want it all be obscure trivia. Some obscurity and pedantry should be fine.



  • I'm not really a C++ programmer, but aren't structs allocated on the stack while class objects are usually allocated on the heap?



  • @powerlord said in 10 questions to determine familiarity with C++:

    I'm not really a C++ programmer, but aren't structs allocated on the stack while class objects are usually allocated on the heap?

    No, that's C#.



  • @powerlord Heh, that's the kind of misconception I was hunting for. Something a newcomer to the language might not be certain about, but someone who's used it for a while knows. No, language-wise, they're completely equivalent except that classes default to private members and inheritance, and structs default to public members and inheritance. Also, in C++ at least, the proper terms are automatic and dynamic lifetime, not stack and heap.



  • @dcon said in 10 questions to determine familiarity with C++:

    No, that's C#.

    In C#, the structs are allocated on the you don't know or care and the class objects are also allocated on the you don't know or care.



  • @powerlord said in 10 questions to determine familiarity with C++:

    I'm not really a C++ programmer, but aren't structs allocated on the stack while class objects are usually allocated on the heap?

    C#... or really .net in general. Because .net is a managed memory environment, it has its own rules for how its heap (where managed memory resides) is handled. And that rule is part of it... though even then, that rule is only a technicality. Struct values can be in the heap if they're boxed in some way, may that be if you polymorphically box it by casting it to a interface or as 'object'. Or because it's a member of a managed type, like a class, as a field member. It then would technically reside on the heap representing the state of the object it is a member of.

    C# gets its syntax and name from C++ because it syntactically resembles it (though it more resembles Java, but since that borrowed from C++... you know... history and shit). C++'s class isn't really anything much different from its struct, only that it defaults to private members... and that's primarily because OOP standards prefer encapsulated data types, so fields should be private by default. Aside from that, there's really no difference... it allows for developers to abide to conventions... so conventionally a C++ developer would choose class for types that will be treated as obejcts, and structs for types treated as simple data structures.


  • BINNED

    @blakeyrat said in 10 questions to determine familiarity with C++:

    @dcon said in 10 questions to determine familiarity with C++:

    No, that's C#.

    In C#, the structs are allocated on the you don't know or care and the class objects are also allocated on the you don't know or care.

    Yeah, it's pure implementation detail. The difference that matters in C# is between value types and reference types.

    To answer the OP, I'm a fan of the "what would you change about this code?" type question. You could even have one sample with a selection of stylisticly questionable elements, subtle bugs, inconsistencies etc. and see how many they spot in the time. This would allow for C++ specific stuff alongside more general logic and stuff



  • @accalia said in 10 questions to determine familiarity with C++:

    we need to flip E to verify that there is an even number on it to satisfy the rule, and we need to flip 5 to verify that the value on the back is NOT a vowel becasue otherwise we hava a violation of the rule.

    Why would you need to flip the 5?

    See also: Affirming the consequent.


  • sockdevs

    @powerlord said in 10 questions to determine familiarity with C++:

    Why would you need to flip the 5?

    @lordofduct said in 10 questions to determine familiarity with C++:

    if a card has a vowel, the number on the other side must be an even number

    Because if the 5 has a vowel on the back the stated rule is violated. and thus false. I need to confirm that it is a consonant on the back of the 5 .

    vowels must have an even number on the back, therefore there must not be a vowel on the back of a odd number, five is odd and thus must have a consequence.


  • Discourse touched me in a no-no place

    @Kian said in 10 questions to determine familiarity with C++:

    Something about templates, but hard to think of a multiple choice question with them.

    Some mention of CRTP?


  • Discourse touched me in a no-no place

    @Groaner said in 10 questions to determine familiarity with C++:

    "Do you see anything in this code that you would change?"

    Other than the obvious one, "your { placement is stupid" ?



  • @Jaloopa said in 10 questions to determine familiarity with C++:

    You could even have one sample with a selection of stylisticly questionable elements, subtle bugs, inconsistencies etc. and see how many they spot in the time.

    I liked that one for exactly that reason; it did have more than one thing to change.



  • @lordofduct said in 10 questions to determine familiarity with C++:

    Part 1 - determine logical abilities (language independent)
    Your first few questions could be logics based. One of my favourites is:
    There is a deck of cards on one side of which are letters, and the other side of which are numbers. There is 1 rule:
    if a card has a vowel, the number on the other side must be an even number
    4 cards are dealt in random order/facing:
    E 4 5 L

    I've read that this test is only hard when presented as an abstract logic puzzle. Most people will get the following social version correct:

    There is a deck of cards on one side of which are names of drinks, and the other side of which are numbers representing the age of a person. There is 1 rule:
    If a card has an alcoholic drink, the age on the other side must be greater than or equal to 21.
    4 cards are dealt in random order/facing:
    Beer 35 17 Water

    Most people will correctly choose Beer and 17.

    @Groaner said in 10 questions to determine familiarity with C++:

    Here's one that was a real interview question put in front of me:
    class vertex {
    public:
    float x,y,z;

    // snip getters and setters and red herrings
    static vertex *create()
    {
    vertex v;
    return &v;
    }
    };

    "Do you see anything in this code that you would change?"

    I like this one. Undefined behavior is always fun.

    Other ideas:

    vector<int> v;
    // Insert line here
    v[0] = 1;
    

    Which of the following is the correct line to insert?
    A. v.size() = 1;
    B. v.capacity() = 1;
    C. v.resize(1);
    D. v.reserve(1);

    Bonus question: which incorrect answer will still compile, leading to mysterious bugs and crashes? Why?


    Given

    class A
    {
        // stuff
    };
    class B : public A
    {
        // more stuff
    };
    

    which of the following vectors can hold instances of both A and B? (Two correct answers)
    A. vector<A> v;
    B. vector<B> v;
    C. vector<A&> v;
    D. vector<A*> v;

    Of the two answers, which is the correct choice in an actual program? Why?



  • @FrostCat said in 10 questions to determine familiarity with C++:

    @Groaner said in 10 questions to determine familiarity with C++:

    "Do you see anything in this code that you would change?"

    Other than the obvious one, "your { placement is stupid" ?

    That was entered on mobile. If you have suggestions for an easy means of autoindenting therein, I'm all ears.


  • Discourse touched me in a no-no place

    @Groaner said in 10 questions to determine familiarity with C++:

    That was entered on mobile.

    :whoosh: ?


  • BINNED

    @Kian Other than 2 and 1 (aah I hate trivia questions), where is C++? Also if you ask C++ not C++11 then you are :doing_it_wrong: . Seriously, C++ (not C++14+) is shit.



  • @Groaner said in 10 questions to determine familiarity with C++:

    Here's one that was a real interview question put in front of me:

    class vertex {
    public:
    float x,y,z;
    
    // snip getters and setters and red herrings
    static vertex *create()
    {
    vertex v;
    return &v;
    }
    };
    

    "Do you see anything in this code that you would change?"

    That would totally work in Go.



  • @MZH said in 10 questions to determine familiarity with C++:

    which of the following vectors can hold instances of both A and B? (Two correct answers)
    A. vector<A> v;
    B. vector<B> v;
    C. vector<A&> v;
    D. vector<A*> v;

    Of the two answers, which is the correct choice in an actual program? Why?

    Actually, none of those can. A and B are obviously wrong, but C and D hold instances of A*, not instances of A or B.


  • Winner of the 2016 Presidential Election

    @ben_lubar said in 10 questions to determine familiarity with C++:

    Actually, none of those can. A and B are obviously wrong, but C and D hold instances of A*, not instances of A or B.

    Instances of pointers? :wtf: I think we're getting at covariance vs contravariance. B "is a" A so you can put Bs in a collection of As.

    I think. Last time I used C++ was 10 years ago.

    Again, makes more sense when you give them concrete names. You can put Squares in a collection of Rectangles, obviously, but not Rectangles in a collection of Squares.



  • @ben_lubar Perhaps "instance" is the wrong word. I meant something more general like holding "data" of type A and B. Object or pointer doesn't matter. The answers I was going for were A and D, with mention of the slicing problem of answer A as the bonus.

    Demonstration here: http://ideone.com/XLS2Lf



  • @MZH said in 10 questions to determine familiarity with C++:

    Object or pointer doesn't matter.

    There are four different types in this question:

    A is a class with some stuff in it.
    B is a class inheriting from A with some more stuff in it.
    A* is a pointer to either A or B, assuming no other types are defined in the program.
    A& is syntactic sugar for A* but dereference it all the time.

    The std::vector<A*> and std::vector<A&> types (which are actually the same type) don't hold data of type A or data of type B. They hold data of type A*, which points to data of either type A or type B.

    It's an important distinction that Tactician Goomf would be very proud of.



  • @MZH said in 10 questions to determine familiarity with C++:

    Object or pointer doesn't matter.

    That, right there? Everything that's wrong with modern languages.



  • @ben_lubar All true (:pendant: or otherwise). The other important point is that answers B and C lead to code that won't compile. B b = A() is a type error and std::vector<A&> won't compile since C++ references aren't assignable.

    @flabdablet said in 10 questions to determine familiarity with C++:

    @MZH said in 10 questions to determine familiarity with C++:

    Object or pointer doesn't matter.

    That, right there? Everything that's wrong with modern languages.

    Also, yes. I like Python except for this:

    a = [1, 2, 3]
    b = a
    a.append(4)
    print(b) # [1, 2, 3, 4]  <-- ???

Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.