I can not really resolve, why do I get the unexpected return value in this code:
#include <stdio.h>
typedef union ku {
struct {
int x;
int y;
} sd;
int id;
} ku_type;
ku_type kuReturner() {
ku_type ku;
ku.sd.x = 11;
ku.sd.y = 22;
ku.id = 99;
return ku;
}
int main()
{
ku_type ku;
ku = kuReturner();
// returns '99', it is not expected value
// expected value must be '11'
printf("%d", ku.sd.x);
return 0;
}
I have tried to define struct outside the union and create a struct variable inside union, but the result was always the same. Where do I have a mistake?