-2

I've tried to figure out what is the output of a code like this .By the way ,It is not a real question, kind of therical question, i mean it is not an original c code, it is kind of a PL having c-code syntax and passed by name parameter paradigm.

int x=12,y=10;
void tswap(int pa, int pb) {
int tmp;
tmp=pa;
pa=pb;
pb=tmp;
x=x+pa;
x=x-pb;
y++;
printf("%d %d %d %d\n",pa,pb,x,y);
}

int main() {
int a=4;
tswap(x,a);
printf("%d %d %d\n",x,y,a);
tswap(++x,++y);
printf("%d %d %d\n",x,y,a);
return 0;
}

I think the output of first part should be :

-4 12 -4 11
-4 11 12

But i could find a logical solution for the part tswap (++x, ++y) Is there anyone who can know how can I handle with this part ?

Thanks in advance !

4

1 回答 1

1
tswap(++x,++y) 

is the same as:

++x;
++y;
tswap(x,y);

making your output:

4 12 4 11
4 11 4
12 5 12 13
12 13 4
于 2013-04-08T23:06:37.783 回答