Home > Back-end >  Call in the pointer as a function parameter
Call in the pointer as a function parameter

Time:09-30

This is the source code, but the output value has been the address name instead of the stored value, feel confused, please leaders to help see
#include
The main ()
{
Int Max (int, int);
Int min (int, int);
Int the add (int, int);
Void process (int, int, int (* fun) (int, int));
Int a, b;
The scanf (" % d % d ", & amp; A, & amp; B);
The process (a, b, Max);
Printf (" Max=% d ");
The process (a, b, min);
Printf (" min=% d ");
The process (a, b, add);
Printf (" add=% d ");

}
Int Max (int x, int y)
{
Int z;
If (x> Y)
{
Z=x;
}
The else
{
Z=y;
}
Return the z;
}
Int min (int x, int y)
{
Int z;
If (x> Y)
{
Z=y;
}
The else
{
Z=x;
}
Return the z;
}
Int the add (int x, int y)
{
Int z;
Z=x + y;
Return the z;
}
Void process (int x, int y, int (* fun) (int x, int y))
{
Printf (" % d \ n ", fun (*) (x, y));
}

CodePudding user response:

Put the printf statements in front can be normal output process function called
 
#include

Int main ()
{
Int Max (int, int);
Int min (int, int);
Int the add (int, int);
Void process (int, int, int (* fun) (int, int));
Int a, b;
The scanf (" % d % d ", & amp; A, & amp; B);
Printf (" Max=");
The process (a, b, Max);
Printf (" min=");
The process (a, b, min);
Printf (" add=");
The process (a, b, add);
}

Int Max (int x, int y)
{
Int z;
If (x> Y)
{
Z=x;
}
The else
{
Z=y;
}
Return the z;
}

Int min (int x, int y)
{
Int z;
If (x> Y)
{
Z=y;
}
The else
{
Z=x;
}
Return the z;
}

Int the add (int x, int y)
{
Int z;
Z=x + y;
Return the z;
}

Void process (int x, int y, int (* fun) (int x, int y))
{
Printf (" % d \ n ", fun (*) (x, y));
}

CodePudding user response:

 # include 

Int main ()
{
Int Max (int, int);
Int min (int, int);
Int the add (int, int);
Void process (int, int, int (* fun) (int, int));
Int a, b;
The scanf (" % d % d ", & amp; A, & amp; B);
Printf (" Max=");
The process (a, b, Max);
//printf (" Max=% d ");
Printf (" min=");
The process (a, b, min);
//printf (" min=% d ");
Printf (" add=");
The process (a, b, add);
//printf (" add=% d ");

}
Int Max (int x, int y)
{
Int z;
If (x> Y)
{
Z=x;
}
The else
{
Z=y;
}
Return the z;
}

Int min (int x, int y)
{
Int z;
If (x> Y)
{
Z=y;
}
The else
{
Z=x;
}
Return the z;
}
Int the add (int x, int y)
{
Int z;
Z=x + y;
Return the z;
}
Void process (int x, int y, int (* fun) (int x, int y))
{
//printf (" % d \ n ", fun (*) (x, y));
Printf (" % d \ n ", fun (x, y));
}

For your reference ~
  • Related