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 7 of 10.

Sivamoorthy said:   1 decade ago
The return function to return only one value.
Return(x); is true.
Return (x,y) is false it error.

Rrrr said:   10 years ago
But here the return case we not suppose to do like that it is not possible so it will get error.

Nikhil said:   1 decade ago
Function returns values even in following two cases.

1) return a, return b;

2) return (2, 4);

Abhishek said:   8 years ago
Here return (kk, ll); it will return only kk as RETURN only return one value i.e first one.

Shakti singh said:   1 decade ago
LL is only returning values for both variables because KK is being overwritten by LL.

Kutrapali said:   7 years ago
Why does it return value? I thought the variable "kk" is not equals to variable "k".

Siri said:   9 years ago
Why doesn't the value '12' return to k in the next turn? Why should it go to the l?

VANSHIKA said:   4 years ago
This function is not having a prototype so why isn't it is having compile error.

Sukannya said:   1 decade ago
A function can return only one value at a time. So, return(kk, ll) is invalid.

Shruti said:   3 years ago
The last value is returned and all the values before that are simply ignored.


Post your comments here:

Your comments will be displayed after verification.