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.
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; }; };
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
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.
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
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. :)
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_; }
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.
All of your videos are really educative. You make learning all concepts so easy and clear. Thanks. Keep it up ☺️
Thanks for such a nice comment!!
So many tutorials are difficult to understand. Thank you for being so clear
Welcome dude..
Your tutorial concept is easy to understand, great tutorial. 😊👍
Thanks for the comment dude.
How do you know in your system memory is reading addresses from right to left ?? I mean what is the way to know this ??
What is the IDE you use ?
Sublime text editor.
@@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.
Hi Sir. Please explain
when we use std::string data member in union while compiling, the compiler is throwing an error.
please show me the code.
excellent and perfect
Thanks for your comment!!
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;
};
};
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 ?
same doubt for me also@CppNuts
Amazing
Thanks dude!!
Hi CPP nuts. Can you please add interview questions on Linux and it's internals.?
Dude, that will take time.
Ok bro I'm waiting for those videos.
@@CppNuts I am still waiting sir....
No time man... so much busy.. sometimes life doesn't give you breathing time is what i am going through.
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
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.
CppNuts welcome bro
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
Good :)
Thanks man!!
ferfect)
Thanks man!!
No videos? since 3 weeks!!!!
So much busy dude.
oh, so when can we expect new videos? ,Please step into advance topics like multithreading, File I/O etc, Thanks
Ravi, sure but i have already started this C++ basic series and i think i should complete this one first.
Sorry for delay!!
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. :)
Thanks for your advice I will think about it
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_;
}
Unions are like enums in c++
No they are very different from each other.
They are totally different.