+ 4
when function foo(x,y) is called, will not then the value of n assigned to x and that of m to y? Help please!
#include<stdio.h> void foo(int n,int m) { n = 11; m = 93; //printf("%d %d\n",n,m); } int main() { int x =7, y =4; foo(x,y); printf("%d ",x); printf("%d",y); return 0; }
4 Réponses
+ 4
7 and 4 will be output
Because here we are passing bu value
So value of variable x and y will be passed which will be copied in n and m respectively
Once v make change in n and m that won't affect x and y because x and y has different memory address
+ 3
A hint. Add these lines...
...to foo():
printf("--> n:%x m:%x <--\n", &n, &m);
...to main():
printf("--> x:%x y:%x <--\n", &x, &y);
Output: The addresses of each variable in memory.
+ 2
...and they have different addresses because 'n' and 'm' are 'local' to foo.
Space is allocated for these local variables on a temporary 'stack' when the function is called, and this memory is released when the function returns.
0
[redacted] Mason Mixdorf Please don't post spam-like comments and please do review...
https://www.sololearn.com/discuss/321242/?ref=app
https://www.sololearn.com/discuss/1316935/?ref=app