In a graphics program, you need to define colors where each color can be represented as either a name or an RGB triplet. How would you efficiently represent this in C?
- Using a function
- Using a structure
- Using a union
- Using an enum
In C, a union would efficiently represent colors that can be either a name or an RGB triplet because it allows sharing the same memory location for different data types. Enums, structures, and functions are not suitable for this purpose.
Loading...
Related Quiz
- What is the return type of the strlen function in C?
- What is the significance of using pointers to arrays in C?
- What will happen if the condition in a 'while' loop is initially false?
- When working with binary files in C, what is the significance of the 'b' character in the mode string?
- Why would a developer use pointers to structures instead of using structures directly?