c*e
1 楼
void swap(int *a, int *b) {
int *c;
*c=*a;
*a=*b;
*b=*c;
return;
}
int main() {
int x=5, y=10;
swap(&x, &y);
cout << x << " " << y << endl;
return 0;
}
The correct result is printed, but there is a segmentation fault. Is it
because *c is a local variable?
int *c;
*c=*a;
*a=*b;
*b=*c;
return;
}
int main() {
int x=5, y=10;
swap(&x, &y);
cout << x << " " << y << endl;
return 0;
}
The correct result is printed, but there is a segmentation fault. Is it
because *c is a local variable?