C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 2)
2.
What will be the output of the program ?
#include<stdio.h>
int main()
{
union var
{
int a, b;
};
union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
return 0;
}
Discussion:
83 comments Page 6 of 9.
Anu said:
1 decade ago
Since union shares the same memory space, the value gets overwritten.
Mitha mazumdar said:
1 decade ago
But 'c' cannot create objects as java does so how it is possible?
Karan said:
6 years ago
How it will print 20? I am not getting, please anyone tell me.
(1)
Nitish anand said:
1 decade ago
Union allocate memory only for which have large memory size.
Rajadurai said:
2 decades ago
Union allocate memory only for which have large memory size.
Sathya said:
1 decade ago
How it will print 20? I can't understand please explain it.
Rashed said:
10 years ago
I didn't understand how it becomes 20 it must be 10.
Suprajanarayan said:
1 decade ago
What will be defined at last that will be printed?
TALLURI NARESH said:
1 decade ago
Memory is allocated the max size of the elements.
Reshma said:
9 years ago
Union allocates memory for the large memory size.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers