void swap(int &first, int &second){
int temp = first;
first = second;
second = temp;
}
int a=3,b=2;
swap(a,b);
The compiler complaints that void swap(int &first, int &second)
has a syntax error. Why? Doesn't C support references?
C doesn't support passing by reference; that's a C++ feature. You'll have to pass pointers instead.
void swap(int *first, int *second){
int temp = *first;
*first = *second;
*second = temp;
}
int a=3,b=2;
swap(&a,&b);