return value of return

return can only return one value: a numeric value or a pointer value.
Need to return multiple values, the simple way is to pass through the function parameters.

return j, k; is fine, the syntax is correct, because it returns the value of an expression. Here is the "comma expression":
j, k; the
result of the "calculation" of the comma expression is the last expression separated by commas, where j is an expression and k is an expression;
return j, k; returns k
return k, j; return j
you can try:
#include <stdio.h>
int fun ()
{
int k = 1, j = 3;
return j, k; // or try return k, j;
}
void main ()
{
int x;
x = fun ();
printf ("% d", x);
getch ();
}

Guess you like

Origin www.cnblogs.com/zycs/p/12656020.html