Home > Back-end >  With Pointers to determine size, why not come?
With Pointers to determine size, why not come?

Time:03-12

# include
Void adjust (int * (p1, p2 int *)
{
Int * p3;
If (* p1 & lt; * (p2)
{
P3=p;
P1=p2;
The p2=p3;
}
}
Int main ()
{
Math1 int a1, a2, * and * math2;
Math1=& amp; A1.
Math2=& amp; A2.
The scanf (" % d % d \ n ", & amp; A1, & amp; A2);
Adjust (math1, math2);
Printf (" % d % d \ n ", * math1, * math2);
return 0;


}

CodePudding user response:

Reference:
 # include 
Void adjust1 (int * (p1, p2 int *)//pointer p1 p2 scope in this function, so to change their values,
//not back to the math1 math2, so is invalid,
{
Int * p3;
If (* p1 & lt; * (p2)
{
P3=p;
P1=p2;
The p2=p3;
}
}

Void adjust2 (int * (p1, p2 int *)//to the pointer points to the value of the operation is effective
{
Int p3;
If (* p1 & lt; * (p2)
{
P1 p3=*;
* p1=* (p2);
* the p2=p3;
}
}

Int main ()
{
Math1 int a1, a2, * and * math2;
Math1=& amp; A1.
Math2=& amp; A2.
The scanf (" % d % d ", & amp; A1, & amp; A2);//the scanf (" % d % d \ n ", & amp; A1, & amp; A2); There is much more '\ n'

Adjust1 (math1, math2);
Adjust1: printf (" % d % d \ n ", * math1, * math2);

Adjust2 (math1, math2);
Adjust2: printf (" % d % d \ n ", * math1, * math2);

return 0;
}

CodePudding user response:

In-depth study Pointers and references, as well as the function scope and return values
  • Related