-3

I came across this code and want to know what this line [X] will it return:

int add_multiply(int a, int b)
{
  int p, q;
  p = a + b;
  q = a * b;
  return (p, q); //X
}
void main()
{
  int b, a = add_multiply(1, 2);
  b = add_multiply(3, 4);
  printf("%d%d", a, b);
}
yuyoyuppe
  • 1,582
  • 2
  • 20
  • 33
Jagdeepak
  • 1
  • 2

1 Answers1

7

You can't return more than one variable at once from a function in C. The statement

return(p, q); // or return p, q; 

returns q only. The , in p, q is a comma operator. p will be evaluated and it's value will be discarded, then q will be evaluated and then its value will be returned.

haccks
  • 104,019
  • 25
  • 176
  • 264