I can't understand the answer to the following question. Please help me :)
what is the output:
struct INT
{
int i;
};
typedef struct INT INT;
int Change(INT** INTptr)
{
(*INTptr) = (INT*)malloc(sizeof(INT));
(*INTptr)->i = 1000;
return 500;
}
int main()
{
INT dummy = {750};
INT* ptr = &dummy;
ptr->i = Change(&ptr);
printf("dummy.i = %d, ptr->i = %d\n", dummy.i, ptr->i);
return 0;
}
Got this from a friend of mine.
I thought the answer would be:
dummy.i = 750, ptr->i = 500
but when I run the code (GCC compiler) I get:
dummy.i = 500, ptr->i = 1000
can it be my answer with a different compiler?
Moreover, I still don't understand why the output is 500 and 1000...
thanks in advance!