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 7 of 9.
Doni said:
2 decades ago
Srivdiya n Risbah answers are good.
RamDas said:
2 decades ago
Sridivya your answer is good
Maddy said:
2 decades ago
Nice expalanation vedavathi.
Nadeem said:
2 decades ago
@rajadurai
Union may have collection of different datatypes. so, it allocates the memory of the largest data type.
Ex:
union xyz{
int x;
float y;
double z;
};
It allocates only 8 bytes for whole. Agree?
Union may have collection of different datatypes. so, it allocates the memory of the largest data type.
Ex:
union xyz{
int x;
float y;
double z;
};
It allocates only 8 bytes for whole. Agree?
Jyoti pandey said:
2 decades ago
Rajadurai is wrong.
Union not allocate for large memory size.
It allocate the last overrided value Whether it is large or small
Union not allocate for large memory size.
It allocate the last overrided value Whether it is large or small
Karpakam said:
2 decades ago
Good explanation Viswakethu.A
Vandana said:
2 decades ago
At first union stores large value into memory, so we Will get 20 as output.
Ashish said:
2 decades ago
Good answer Dinesh.....
Atul tailwal said:
2 decades ago
I agree to Rishabh
Divya said:
2 decades ago
Good answer Srividhya & Rishabh
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers