Given this piece of code

void swap(int x, int y)
{ x= x + y;
y= x - y;
x= x - y;
}

main ()
{ i = 1;
a[0]=2;
a[1]=1;
a[2]=0;
swap(i,a[i]);
printf("%d %d %d %d\n", i, a[0], a[1], a[2]);
swap(a[i], a[i])
printf("%d %d %d %d\n", i, a[0], a[1], a[2]);
return 0;
}

what will be printed out

hope some one can help

in main() the values of i and the elements of a remain unchanged since you are passing both parameters to swap() by value, not by reference.

You know of course that you will need to declare an array of int called a before you could successfully compile and run the code, yes?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.