+ 2

Find the error I

Please help to find error https://code.sololearn.com/cP1x6Aj0hHx5/?ref=app

1st Jan 2021, 1:04 PM
Mehrob Abdulvahobov
Mehrob Abdulvahobov - avatar
3 Antworten
+ 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; }
1st Jan 2021, 1:32 PM
Flash
+ 3
Thanks 😘
11th Jan 2021, 3:54 PM
Mehrob Abdulvahobov
Mehrob Abdulvahobov - avatar
+ 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; }
1st Jan 2021, 1:35 PM
Flash