Advertisemen
Something I realised the other day and forget to write down until now:
void swap_ref(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void swap_add(int &a, int &b)
{
int temp = a;
a = b;
b = temp;
}
These two function do exactly the same thing - swap the values of a and b. The int &a, was created by C++ to stop the unsightly pointers being used. Just keeps code cleaner.
Advertisemen
Tidak ada komentar:
Posting Komentar