C Programming - Functions - Discussion

Discussion Forum : Functions - Find Output of Program (Q.No. 12)
12.
What will be the output of the program?
#include<stdio.h>

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

int main()
{
    int i=3, j=4, k, l;
    k = addmult(i, j);
    l = addmult(i, j);
    printf("%d %d\n", k, l);
    return 0;
}
12 12
No error, No output
Error: Compile error
None of above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
91 comments Page 6 of 10.

Rohan said:   1 decade ago
Let a = 15 and b = 16.

Return (b = a+b, b);

Value return will be 31.

This may clear the left to right associativity of operator.

Nipun kumari said:   1 decade ago
Since it is returning the value as ll=12 then please make me clear that is this value will be stored for both ll and kk both?

Sahana said:   1 decade ago
During assignment, comma operator process from right to left. While during return operations, it process from left to right.

Verma said:   1 decade ago
Answer is right, here it will return last return value.

If function is returning return(i,j); then value of j will return.

Delhidurai said:   9 years ago
Guys, a function can return only one value at a time. Thus the statement is invalid. Then how will come this answer 12 12?

Debayani said:   5 years ago
Hi, it is call by value not call by reference so the value should not get change, it should print 3 and 4. Am I right?

Janhavi said:   1 decade ago
@Prashanthi.

i and j value does not change when you return back to the calling function from the called function.

Shubh said:   6 years ago
Case-1
return(10,20);
It will return only 20.

Case-2
return 10;
return 20;
It return first statement only.

ALOK patro said:   9 years ago
Hi @Preethi.

The description which you have given is not understable to me.

Please explain briefly.

Ayush sharma said:   7 years ago
It is not possible to return multiple values through return keywords. So I think it's a wrong answer.


Post your comments here:

Your comments will be displayed after verification.