Home > Back-end >  Pointer related problems for help
Pointer related problems for help

Time:09-22

Pointer just began to learn, feel learning is a little confusing,,, want to ask the bosses specific problem-solving ideas, thank you,

The following program is run right result is (),

#include

Four (int x, int y)

{

Int z;

Z=x; X=y; Y=z;

return;

}

The main ()

{

Int a=9; B=5;

Ptr1 int x, y, * and * ptr2 will;

Ptr1=& amp; x;

Ptr2 will=& amp; y;

* ptr1=a + b;

* ptr2 will=a - b;

Ptr2 will ptr1, four (* *);

Printf (" % d, % d \ n ", x, y);

}

CodePudding user response:

Four that function is equivalent to do nothing, because what also can't change, the equivalent of a + b, a - b, so the final result is that the output of 14, 4

CodePudding user response:

There are two errors in the code
 # include & lt; stdio.h> 

Void four (int x, int y)//-- -- -- -- -- -- -- -- -- -- -- -- with void indicates no return value -- -- -- -- -- -- -- --

{

Int z;

Z=x; X=y; Y=z;

return;

}
Int main ()
{
Int a=9, b=5;//-- -- -- -- -- -- -- -- a semicolon instead of a comma between a and b -- -- -- -- -- -- -- --

Ptr1 int x, y, * and * ptr2 will;

Ptr1=& amp; x;

Ptr2 will=& amp; y;

* ptr1=a + b;

* ptr2 will=a - b;

Ptr2 will ptr1, four (* *);

Printf (" % d, % d \ n ", x, y);
return 0;
}

Because the four parameters () function is int, belongs to the reference parameters, so the function inside will not change the value of the argument, as a result, the value of x is a + b, y is a - b, the output of 14 and 4,
For reference and the reference, please refer to "function in c + + array parameter" wish I could help you!
  • Related