Hello,
Could anyone explain details about three different case and output. Here is the code and output:
#include <stdio.h>
void foo(int n)
{
n = 6;
}
void fooWithRef(int& n)
{
n = 6;
}
int main()
{
int n;
foo(n);
printf("Case_1 Result: %d \n", n);
n = 4;
foo(n);
printf("Case_2 Result: %d \n", n);
fooWithRef(n);
printf("Case_3 Result: %d", n);
}
Output:Case_1 Result: 134521641
Case_2 Result: 4
Case_3 Result: 6
Please discuss the reasons about the different outputs.
Thanks.