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;
}
Discussion:
91 comments Page 9 of 10.
Preethi said:
1 decade ago
#include<stdio.h>
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;
}
int addmult(int ii, int jj)
{
int kk, ll;
kk = ii + jj;
ll = ii * jj;
return(kk);
return(ll);
}
If the program is rewritten as shown above the output is 7 7 how is it possible?
Can any one explain me please?
K.brahmateja said:
1 decade ago
In the return statement if there is more than one argument, it will the rightmost argument value will be sent to the calling function.
In this program we have return(kk,ll) the rightmost argument here is ll, in the definition ll is assigned to multiplication of the two variables only i.e " 3*4 =12".
In this program we have return(kk,ll) the rightmost argument here is ll, in the definition ll is assigned to multiplication of the two variables only i.e " 3*4 =12".
Sharenu said:
1 decade ago
Thank you @sundar. But how to differentiate comma and comma opertor. Where are the comma operators necessary. Can you please explain me.
Pravu said:
1 decade ago
@Prashanthi.
It depend on whether you are changing the value in called function or not if you are catching value of I and j through pointer or address and if you are doing any operation in called function then sure the original value of I and j get changed.
It depend on whether you are changing the value in called function or not if you are catching value of I and j through pointer or address and if you are doing any operation in called function then sure the original value of I and j get changed.
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.
i and j value does not change when you return back to the calling function from the called function.
Prashanthi said:
1 decade ago
Hi.
Please help(Not regarding this problem).
When a return stmt is returned the control goes back from the called function to the calling function i.e(for example)here it goes to K = addmult(i,j).
My doubt is whether i, j values get preserved(remain 3,4) or do they change if we have done sth to the values of i, j in the called function?
Suppose after return statement we have sth to do with i, j. Please answer.
Please help(Not regarding this problem).
When a return stmt is returned the control goes back from the called function to the calling function i.e(for example)here it goes to K = addmult(i,j).
My doubt is whether i, j values get preserved(remain 3,4) or do they change if we have done sth to the values of i, j in the called function?
Suppose after return statement we have sth to do with i, j. Please answer.
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.
Sunil kumar said:
1 decade ago
In this prg we can get the value
k=(7,12) and l=(7,12).
In here the comma operator and brackets performs the right to lift.
So that way only it prints 12 and 12.
We can assign k = 7,12 and l = 7,12.
That time we can got 7 and 7 is the output in here it will working in left to right.
k=(7,12) and l=(7,12).
In here the comma operator and brackets performs the right to lift.
So that way only it prints 12 and 12.
We can assign k = 7,12 and l = 7,12.
That time we can got 7 and 7 is the output in here it will working in left to right.
Sukannya said:
1 decade ago
A function can return only one value at a time. So, return(kk, ll) is invalid.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers