Top 5 C++ Interview Questions to Test Your Programming Prowess

Поділитися
Вставка
  • Опубліковано 24 сер 2024

КОМЕНТАРІ • 24

  • @ivayloi736
    @ivayloi736 5 років тому +8

    I'll give this guy 6 of 10. Q1 + Q2 are quite stupid, you should never mess with the stack and heap in a way that was not intended. If you are not a compiler developer - end of discussion... Size of the structs matter even today in many cases, for example - keeping cache alignment, when working with GPUs. #ifdef #endif have a lot of usages. Include guards are not the best example, since most compilers have #pragma once which is faster. NULL is basically for C programming, while nullptr is for C++. NULL is still used in legacy code, low level WIN32 programming, and one should follow the general convention there.

  • @icecog
    @icecog 5 років тому +4

    Q1. If the local variable is living in stack frame of another thread, the access of that memory piece is valid through a pointer from another thread until the threads are running. Although some lifetime management and synchronisation are needed.
    Q3: Size of the structs can be important regarding different communication protocols and their packets.

  • @JayAnAm
    @JayAnAm 5 років тому +3

    Q3: So designing it like this makes more sense, right?
    struct TStruct
    {
    char a;
    char b;
    short c;
    int d;
    };

    • @kseniarogova630
      @kseniarogova630 5 років тому +1

      Yes.
      I'd recommend u to read smth about data structure alignment in C++. Actually, it's very cool to understand how architecture of computer processor manage all this work with memory and why on earth this padding happened.

  • @Gargantupimp
    @Gargantupimp 5 років тому +1

    Thanks man

  • @rishiniranjan1746
    @rishiniranjan1746 28 днів тому

    Microsoft asks such school level questions.😅Shame !

  • @roarraizzer9529
    @roarraizzer9529 5 років тому +3

    useful info: keyword new - calls the constructor
    keyword delete - calls the destructor.
    Hit like, if you didn't know 'bout this.

  • @samacumen
    @samacumen 6 років тому

    Great job!

  • @spicytuna08
    @spicytuna08 6 років тому +1

    #1, create another dummy function. this will most likely prove your point.

  • @fatimanaeem3993
    @fatimanaeem3993 5 років тому +2

    He looks so much like benedict. :D

  • @dumbcro
    @dumbcro 18 днів тому

    hahaha the laugh stock comment is: "this was a concern back in the days when memory size was a concern". My man, you do embedded nowadays and you better mind the memory usage

  • @prashantkulkarni2075
    @prashantkulkarni2075 6 років тому +1

    Awesome

  • @VivekYadav-ds8oz
    @VivekYadav-ds8oz 5 років тому +3

    Isn't that beginner level..?

  • @petersouthwell5971
    @petersouthwell5971 7 місяців тому +1

    It took you forever to get to the point. These don't sound like C++ questions... They're too basic. This is like... Guy right out of college level...?
    Im sure your good man.. I just wanted more questions about the language and less about how pointers work.

    • @petersouthwell5971
      @petersouthwell5971 7 місяців тому

      I mean you didn't cover things like virutal inheritance how it works in multiple inheritance. The new Lambdas C++ supports. The mutex, critical section classes... Whats new in std template library stuff like that...
      You just sorta noodle noised on basic stack allocation during method calls. Is this really how C++ interviews are conducted? I expected more code, patterns and newer features and less explanation about boiler plate interactions of heap and stack.

  • @maxooder
    @maxooder 5 років тому

    call to foo(NULL) is ambiguous in most compilers and leads to a compilation error, it's bad example imo

    • @GrowBullet
      @GrowBullet 5 років тому +1

      what the hell are you talking about NULL is defined as 0 and for compatibilityreasons whidely used instead of nullptr. WTF ^^

    • @maxooder
      @maxooder 5 років тому

      ​@@GrowBullet run cpp.sh/8zqjo, go back to school and do not post your stupid comments

  • @oj0024
    @oj0024 6 років тому

    Eazy

  • @dmitponv4958
    @dmitponv4958 6 років тому +2

    #1. you can do this, if you use shared_ptrs

    • @michaelthompson7217
      @michaelthompson7217 5 років тому +1

      Nice point, but for those reading this is somewhat of a “clever” solution (not in a good way) and I would never say this in an interview. It’s frankly a kludge.
      Any programmer who jumps to this as a potential solution would immediately set off red flags for me. Code would be totally unmanageable, hard to read, dangerously subject to memory leaks.
      If you need dynamic memory, use the heap. If you need to pass values down function calls by reference, you should be passing by reference. If you need static memory, allocate it statically. Don’t do this as a workaround for any of those three.