When do I use a union in C or C++, instead of a struct? @JacobSorber
When do I use a union in C or C++, instead of a struct?  @JacobSorber
Uploaded June 2021 | Updated September 2026, 2 weeks ago
Patreon ➤ patreon.com/jacobsorber
Courses ➤ jacobsorber.thinkific.com
Website ➤ jacobsorber.com
---


When do I use a union in C or C++, instead of a struct? // Unions are useful, but often overlooked in beginner classes, because we don't use them all that much, and because we can often get by without them. This video talks about unions, how they differ from structs, and when you might want to use a union in your C or C++ programs.




***

Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.


About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.

More about me and what I do:
jacobsorber.com
https://people.cs.clemson.edu/~jsorber/
http://persist.cs.clemson.edu/

To Support the Channel:
+ like, subscribe, spread the word
+ contribute via Patreon --- [patreon.com/jacobsorber]

Source code is also available to Patreon supporters. --- [jsorber-youtube-source.herokuapp.com/]
When do I use a union in C or C++, instead of a struct?How to set a socket timeout (setsockopt) in CDoes it matter how I write my infinite loops? (for vs. while?)Should you avoid linked lists? (linked list vs arrays)How to build a web client? (sockets)The Good and Bad of Automatic Make RulesUsing the Smallest C Program to Better Understand Your System (with pmap, vmmap, and strace).How do I access a single bit?PPM might be the best DIY image format (at least for beginners).Why do programmers use hexadecimal numbers?Easy Networking in C (libcurl)Reversing Strings (in C) and Divergent Thinking
Jacob Sorber |

When do I use a union in C or C++, instead of a struct?

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER