C Programming - Memory Allocation - Discussion
Discussion Forum : Memory Allocation - Find Output of Program (Q.No. 4)
4.
What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
union test
{
int i;
float f;
char c;
};
union test *t;
t = (union test *)malloc(sizeof(union test));
t->f = 10.10f;
printf("%f", t->f);
return 0;
}
Discussion:
22 comments Page 3 of 3.
MGR said:
7 years ago
Nice Explanation, Thanks all.
Saif said:
5 years ago
Union allocated with the higher value in it i.e. float the during DMA pointer gets the address of float type then when initialization of value 10.10f is done it will print 10.100000 because float takes 6 digits after the decimal point.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers