-1

Here is my code:

#include <stdio.h>
int thi(int x, int *y) {
    x=*y; 
    *y=2*x; 
    return x+*y;
}

int main () {
    int x=1, y=2; 
    printf("%d, %d, %d", thi(y, &x), x, y);
}

I'm wondering that why the result is 3 1 2. This must be 3 2 2 right?

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523

1 Answers1

-1

No the output 3 1 2 is correct. You would have execute the function before the printf if you want the changes to be made.

Try:

int main () {
    int a=1, b=2;
    int temp = thi(b,&a);
    printf("%d, %d, %d", temp, a, b);
}
Suhaib Ahmad
  • 487
  • 6
  • 25