+ 1
A doubt.
values of x and y are swapped in swap function. as swap is a void type function, then why are x and y swapped in main function?
5 Respostas
+ 2
void swap(int *x, int *y){
int temp=*y;
*y=*x;
*x=temp;
} //what really happened here is that the value is been changed at the address level
swap(&x, &y);
the address of x and y are given as arguments, which means that the values are been changed from the root itself instead of from the surface like pass by value, this method is known as pass by reference
+ 1
Could you leave a link to this code, for better understanding
+ 1
I just realized that. Before u answered....😅. Well thanks btw
0
Its in C tutorial. In more on pointers 3rd topic
0
Can't get the link