1 Answers
C++ Supports 3 types of parameter passing
- Pass By Value
- Pass By Address
- Pass By Reference
Pass By Value
void tryswap(int, int); tryswap(a, b); void tryswap(int x, int y) { int temp = x; x = y; y = temp; }
Pass By Reference
void myswap(int &, int &); myswap(a, b); void myswap(int &r1, int &r2) { int temp = r1; r1 = r2; r2 = temp; }
Pass By Address
void myswap(int *, int *); myswap(&a, &b); void myswap(int *p1, int *p2) { int temp = *p1; *p1 = *p2; *p2 = temp; }