mardi 4 août 2015

Beginner's Query: on C Function return value

I am trying to get some understanding about how pass by value & return are happening in C functions. I cam across a piece of code as follows:

#include <stdio.h>

int fun(int ii, int jj)
{
 int kk, ll;
 kk = ii + jj;
 ll = ii * jj;
 return (kk,ll);
}

int main()
{
 int i=4, j=5, k, l;
 k = fun(i, j);
 l = fun(i, j);
 printf("%d %d\n", k, l);
 return 0;
}

Now apparently I am not getting any errors when I am trying to return 2 values through

fun()

Also, the value that is returned by fun () is "ll" i.e 20 (=4*5) and not "kk". Further, If I rewrite the return statement as :

return (ll,kk);

the value returned is "kk" ie. 9 (=4+5). Query: Why this is so? Thanks!

Aucun commentaire:

Enregistrer un commentaire