C++ Programming Tutorial 44 - Unions

preview_player
Показать описание
🚀 Get 100% Off Your First Month with CustomGPT! 🚀

Sign up for a Standard CustomGPT.ai subscription using my referral link and enjoy 100% off your first month. Plus, you'll help support my channel with a 15% commission at no extra cost to you!

C++ Programming Tutorial 44 - Unions

Source code link

Email us at

Our games made using Cocos2d-x
------------------------------------------------------
Super Jet Bunny

Our games made using Cocos2d
-------------------------------------------------
Glo Breaker

Hundreds of free videos at
Рекомендации по теме
Комментарии
Автор

This is incorrect. Fundamentally incorrect. A union is like a struct, except that ALL of the variables occupy the memory of the largest member. This kind of means that they ALL exist at the same time.

You can easily verify this by printing the "HEX" value instead of the "decimal" value.

If you say "num.d = 6.7", and print as hex, you will get
And guess what? If you print num.i as hex, you will still get

This is convenient since both num.i and num.d contain 32 bits. If one of the members is larger (or smaller), you get stranger behavior....but the key thing to remember is that they ALL exist at the same time. If you initialize one member, ALL of the members get modified (because they all access the same memory).

Sarcasticpigeon
welcome to shbcf.ru