我要添加的两个变量是在main中定义的。
有一个求和函数(假设(。其返回类型为空。变量被传递给这个函数,我想在 main 中打印结果。
您可以像这样定义函数:
void sum( int x, int y, long long int *x_plus_y )
{
*x_plus_y = ( long long int )x + y;
}
其中x_plus_y
是"输出参数"。
这是一个演示程序
#include <stdio.h>
void sum( int x, int y, long long int *x_plus_y )
{
*x_plus_y = ( long long int )x + y;
}
int main( void )
{
int x, y;
printf( "Enter two integer numbers: " );
scanf( "%d%d", &x, &y );
long long int x_plus_y;
printf( "Sum of %d and %d is equal to %lldn",
x, y, ( sum( x, y, &x_plus_y ), x_plus_y ) );
}