Question:

What will be the output of the program? 
#include int main() 
{ union var { int p, q; } u; u.p = 100; u.q = 50; 
printf("%d\n", u.p); 
return 0; }

Show Hint

Unions store all variables in the same memory location — only the last assignment is retained.
Updated On: May 26, 2025
  • 100
  • 50
  • 150
  • Error
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

In a union, all members share the same memory. When `u.q = 50` is assigned, it overwrites `u.p`. So printing `u.p` gives 50.
Was this answer helpful?
0
0