Union In C++

Поделиться
HTML-код
  • Опубликовано: 4 фев 2025

Комментарии • 45

  • @tnamen1307
    @tnamen1307 Год назад +1

    In simplest term...
    A UNION selects and allocates the largest memory among the different data types.
    That means it can used to store only one data at a time. But it can store different types.
    All data types point to the same single memory address.

  • @jyotipandey3422
    @jyotipandey3422 6 лет назад +7

    All of your videos are really educative. You make learning all concepts so easy and clear. Thanks. Keep it up ☺️

    • @CppNuts
      @CppNuts  6 лет назад

      Thanks for such a nice comment!!

  • @desthebest100
    @desthebest100 5 лет назад +2

    So many tutorials are difficult to understand. Thank you for being so clear

    • @CppNuts
      @CppNuts  5 лет назад

      Welcome dude..

  • @rhyanz46
    @rhyanz46 5 лет назад +3

    Your tutorial concept is easy to understand, great tutorial. 😊👍

    • @CppNuts
      @CppNuts  5 лет назад

      Thanks for the comment dude.

  • @cid007007
    @cid007007 4 года назад

    How do you know in your system memory is reading addresses from right to left ?? I mean what is the way to know this ??

  • @AhmedKorany
    @AhmedKorany 6 лет назад +1

    What is the IDE you use ?

    • @CppNuts
      @CppNuts  6 лет назад +2

      Sublime text editor.

    • @DNESHBABU90
      @DNESHBABU90 2 года назад

      ​@@CppNuts how you use the "Marker" to explain the concept in that IDE. like highlighting, drawing..,etc..
      is there an third party sw or separate.

  • @jotirlingswami4426
    @jotirlingswami4426 Год назад

    Hi Sir. Please explain
    when we use std::string data member in union while compiling, the compiler is throwing an error.

    • @CppNuts
      @CppNuts  Год назад

      please show me the code.

  • @nowrasalsalh7666
    @nowrasalsalh7666 6 лет назад +1

    excellent and perfect

    • @CppNuts
      @CppNuts  6 лет назад

      Thanks for your comment!!

  • @bilgetaskn9428
    @bilgetaskn9428 4 года назад

    HIİ PLEASE COULD YOU ANSWER MY QUESTION!!!!!!1
    i saw a code which includes nested union (struct inside union ) . what happes when we write struct inside union like ;
    typedef union{
    uint8_t registervalue;
    struct{
    uint8_t A:4;
    uint8_t B:4;
    };
    };

  • @im_raccoon
    @im_raccoon 4 года назад

    if ur printing the value in binary format then how ur compiler can print 2 in case of un.bytes[0] if un.value=2 ?

    • @rahulr9301
      @rahulr9301 2 года назад

      same doubt for me also@CppNuts

  • @kushalminachi445
    @kushalminachi445 5 лет назад +1

    Amazing

  • @vijaykumar-qf8fe
    @vijaykumar-qf8fe 6 лет назад +1

    Hi CPP nuts. Can you please add interview questions on Linux and it's internals.?

    • @CppNuts
      @CppNuts  6 лет назад

      Dude, that will take time.

    • @vijaykumar-qf8fe
      @vijaykumar-qf8fe 6 лет назад +1

      Ok bro I'm waiting for those videos.

    • @nihaal4699
      @nihaal4699 8 месяцев назад

      @@CppNuts I am still waiting sir....

    • @CppNuts
      @CppNuts  8 месяцев назад

      No time man... so much busy.. sometimes life doesn't give you breathing time is what i am going through.

  • @ahmedrahmane9972
    @ahmedrahmane9972 6 лет назад +3

    Hi bro! There is a really disaster in this video. I agree with you about definition of a union but IT IS UNDEFINED BEHAVIOR TRYING TO ACCESS A MEMBER OF THE UNION THAT IS NOT ACTIVATED. I MEAN THE LAST WRITTEN TO. in your examples you write to value member and accessing the memory from array which is not last activated. value = 257; cout

    • @CppNuts
      @CppNuts  6 лет назад +1

      Yes you are correct about UB, but it should work in almost all the compilers because its about how data is stored in binary formate and then how you are retrieving it. But again IT IS UB. Thanks for the comment it is add-on to this video.

    • @ahmedrahmane9972
      @ahmedrahmane9972 6 лет назад +1

      CppNuts welcome bro

    • @dealvin
      @dealvin 3 года назад

      Acording to you, Union can save memory, I think it's an example about union and enums. Someguy could be helpful this code.
      struct ComplexType{
      enum Type{
      Int,
      Char
      }type;
      union Value{
      int num;
      char ch;
      Value(){}
      ~Value(){}
      }value;
      };
      void DisplayComplexType(const ComplexType& obj){
      switch(obj.type){
      case ComplexType::Int:
      cout

  • @kailashpathak4319
    @kailashpathak4319 6 лет назад +1

    Good :)

  • @alisherrakhimov1997
    @alisherrakhimov1997 6 лет назад +1

    ferfect)

  • @ravikiran6645
    @ravikiran6645 6 лет назад +1

    No videos? since 3 weeks!!!!

    • @CppNuts
      @CppNuts  6 лет назад

      So much busy dude.

    • @ravikiran6645
      @ravikiran6645 6 лет назад +1

      oh, so when can we expect new videos? ,Please step into advance topics like multithreading, File I/O etc, Thanks

    • @CppNuts
      @CppNuts  6 лет назад

      Ravi, sure but i have already started this C++ basic series and i think i should complete this one first.
      Sorry for delay!!

    • @ravikiran6645
      @ravikiran6645 6 лет назад +1

      you can make an roadmap, or probably it would be nice to make a video on what you will cover in basic, intermediate and in advance, so it would be easy for the people to refer it., Just an suggestion. :)

    • @CppNuts
      @CppNuts  6 лет назад

      Thanks for your advice I will think about it

  • @kphuang
    @kphuang 4 года назад

    union Union {
    // Default public
    Union(): c_{0} {} /* This causes unknown data */
    /* Union(): i_{0}, s_{0}, c_{0} {}
    Compilation error only one attribute can be chosen for initialization
    */
    private:
    int i_;
    short s_;
    char c_;
    }

  • @181Ravikiran
    @181Ravikiran 6 лет назад +1

    Unions are like enums in c++

    • @CppNuts
      @CppNuts  6 лет назад

      No they are very different from each other.

    • @joeydicastro
      @joeydicastro 6 лет назад +1

      They are totally different.