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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
C doesn’t support passing by reference. So you will need to use pointers to do what you are trying to achieve:
I do NOT recommend this: But I’ll add it for completeness.
You can use a macro if your parameters have no side-effects.