Hello, everyone I'm Corinne, who started C++ 2 days ago I tried coding as below to implement call by value reference directly.
void Exchange1(int a, int b) { int temp1;
temp1 = a;
a = b;
b = temp1;
}
void Exchange2(int* x, int* y) { int temp2;
temp2 = *x;
*x = *y;
*y = temp2;
int main() { int a, b, x, y;
a = 1;
b = 2;
x = 3;
y = 4;
printf("Before Call-by-value: %d, %d\n", a, b);
Exchange1(a, b);
printf("After Call-by-value: %d, %d\n", a, b);
printf("before swap: %d %d\n", x, y);
Exchange2(x, y);
printf("After swap: %d %d\n", x, y);
return 0;
}
void
No matter how many functions you define, it's the developer's mind. It's just that if you create functions that you don't need, you can'
And if you put the parameter as a pointer, you have to put the address value of the variable like Exchange2 (&x, &y).
© 2024 OneMinuteCode. All rights reserved.