+ 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?

11th Sep 2019, 11:14 PM
Dhruv Baliyan
Dhruv Baliyan - avatar
5 Answers
+ 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
11th Sep 2019, 11:28 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 1
Could you leave a link to this code, for better understanding
11th Sep 2019, 11:15 PM
Dlite
Dlite - avatar
+ 1
I just realized that. Before u answered....😅. Well thanks btw
11th Sep 2019, 11:29 PM
Dhruv Baliyan
Dhruv Baliyan - avatar
0
Its in C tutorial. In more on pointers 3rd topic
11th Sep 2019, 11:18 PM
Dhruv Baliyan
Dhruv Baliyan - avatar
0
Can't get the link
11th Sep 2019, 11:18 PM
Dhruv Baliyan
Dhruv Baliyan - avatar