Home > Back-end >  C language pointer
C language pointer

Time:11-10

# include "stdio.h"

Int * f (int * s, int * t)
{
If (* s<* t)
{
S=t;
}
Return s;
}

Int main ()
{
Int I=3, j=5, * p=& amp; I, * q=& amp; J * r;
R=(p, q);
Printf (" % d, % d, % d, % d, % d \ n ", I, j, * p, * q, *, r);
}
Why this program is running out * p value is 3, should not be 5 ah? For big solutions, thank you very much

CodePudding user response:

P is not pointing to the I? Should not be equal to the I? Do you think which words changed the I, or the value of p

CodePudding user response:

This you need to know about the parameter definition,
In ini * f (int * s, int * t) call process, parameter is a temporary copies of arguments,
That is to say within the function s, t, is the caller p, q) a temporary copy,
So you modify the copy of the value, until after the function, will not affect the
The caller's argument, if you want to change the caller's arguments, you can write

 
Int * f (int * * s, int * * t)
{
If (* * s & lt; * * t)
{
* s=* t;
}
Return * s;
}
  • Related