Why showing error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
23rd Mar 2019, 11:05 AM
Roshan Kumar
Roshan Kumar - avatar
3 Answers
+ 1
Don't use typedef union, just use : union id in the first line This : union id{ int id_num; char name[20]; }id;
23rd Mar 2019, 11:26 AM
RZK 022
RZK 022 - avatar
+ 1
Typedef doesn't work the way you think it does, eg. Typedef struct { // Some data } ID; now ID will be the structure, and then it will work like this : ID Ob; // An object of the structure Eg.2 typedef double Dec; Now you can use Dec as a keyword in place of double Now I will modify your code according to that, and it becomes : #include <stdio.h> #include <string.h> typedef union{ int id_num; char name[20]; }id; void set_id (id *item); void show_id (id item); int main() { id item; set_id(&item); show_id(item); return 0; } void set_id(id *item) { item->id_num = 42; } void show_id(id item) { printf("ID is %d", item.id_num); }
24th Mar 2019, 2:55 AM
RZK 022
RZK 022 - avatar
0
Why
23rd Mar 2019, 2:16 PM
Roshan Kumar
Roshan Kumar - avatar