+ 2
Find the error I
Please help to find error https://code.sololearn.com/cP1x6Aj0hHx5/?ref=app
3 Answers
+ 2
use stack memory.
#include <stdio.h>
union test {
int i;
float f;
char c;
};
int main() {
union test t;
t.f = 10.10f;
printf("%f", t.f);
return 0;
}
+ 3
Thanks đ
+ 2
if you must use heap:
#include <stdio.h>
#include <stdlib.h>
union test {
int i;
float f;
char c;
};
int main() {
union test* t = NULL;
t = malloc(sizeof(union test));
t->f = 10.10f;
printf("%f", t->f);
free(t);
return 0;
}