C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 1)
1.
What will be the output of the program ?
#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);
return 0;
}
Answer: Option
Explanation:
The system will allocate 2 bytes for the union.
The statements u.ch[0]=3; u.ch[1]=2; store data in memory as given below.
Discussion:
40 comments Page 4 of 4.
Krishna said:
1 decade ago
Give full information according (2)(3)=512
Sabi said:
1 decade ago
I can't understand that. How 512 is came?
Aniruddh said:
1 decade ago
Kartik you are absolutely right.
Narmadha said:
1 decade ago
o k k get the binary value k k
Sana Shekijh said:
7 years ago
How to get ui? Please explain.
Pavani said:
2 decades ago
How to get the value of u.i ?
Jyoti pandey said:
1 decade ago
Thanks guys really great.
Saranya devi said:
1 decade ago
Thanks karthick.
Venkatg said:
7 years ago
Thanks @Dash.
Uma said:
1 decade ago
thank u
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers