0
When I invoke swap function, code run properly but when invoke _swap function , it show error
#include <stdio.h> void swap(int a,int b); void _swap(int*a,int*b); int main() { int x = 4,y = 9; _swap(x,y); printf("x = %d & y = %d \n",x,y); return 0; } void swap(int a,int b){ int t = a; a = b; b = t; printf("a = %d & b = %d\n",a,b); } void _swap(int*a,int*b){ int t = *a; *a = *b; *b = t; printf("*a = %d & *b = %d\n",*a,*b); }
2 Antworten
+ 1
Shouldnt you invoke it like
_swap(&x, &y); ???
0
Pointers are used to store address of other variables. Storing direct values is useless and invalid.. So pass address rather than values.