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;
}
10
Garbage value
10.100000
Error
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
22 comments Page 3 of 3.

Shilpa said:   1 decade ago
Thank you. Apple.

I clarified my doubt, with your answer.

Apple said:   1 decade ago
Hi Baru,

Since t->f=10.10f it gives the output as 10.100000 as it float takes 6 digits after the decimal point.


Post your comments here:

Your comments will be displayed after verification.