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 2 of 3.
Sweety said:
1 decade ago
What does f in 10.10f imply?
Hms said:
1 decade ago
What does f in 10.10f imply?
I'd also like to know this, my guess would be that
t->f = 10.10f; equals t->f = 10.10 * f;
But I thought this in the exercise above it would output a garbage value since f was not initialized (ie contains garbage), according to the solution I am wrong.
Could anybody explain this to me?
I'd also like to know this, my guess would be that
t->f = 10.10f; equals t->f = 10.10 * f;
But I thought this in the exercise above it would output a garbage value since f was not initialized (ie contains garbage), according to the solution I am wrong.
Could anybody explain this to me?
Lakshmi prasanna said:
1 decade ago
I can't understand this, please explain from staring any one.
Ltte said:
10 years ago
f tells its float not number*f.
Ganesh said:
10 years ago
t = (union test *)malloc(sizeof(union test));
What value is there in "t"? Can you please explain in detail?
What value is there in "t"? Can you please explain in detail?
Balaji said:
9 years ago
@Ganesh.
t will be holding the address of the pointer pointing to union datatype.
t will be holding the address of the pointer pointing to union datatype.
Rajendra said:
9 years ago
Thanks for the detailed explanation.
MDV AJAY said:
8 years ago
In this, t gets te dynamic address of 4 so it is assigned to f as t->f so 10.10f will becomes 10.100000 now we gotta know that f stands for 4 zeros.
Denish said:
8 years ago
Thanks for the explanation.
Anu said:
7 years ago
thanks all for explaining.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers