C++ Programming - Functions - Discussion

Discussion Forum : Functions - Programs (Q.No. 3)
3.
What will be the output of the following program?
#include<iostream.h> 
void MyFunction(int a, int b = 40)
{
    cout<< " a = "<< a << " b = " << b << endl;
}
int main()
{
    MyFunction(20, 30);
    return 0; 
}
a = 20 b = 40
a = 20 b = 30
a = 20 b = Garbage
a = Garbage b = 40
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
5 comments Page 1 of 1.

Adithya.R said:   8 years ago
Given a=20 and b= 30.

Therefore answer is a=20 b=30.

RAJ said:   10 years ago
Its simple as answer is B since we pass as call the function value is 20 & 30 respectively.

Swati said:   1 decade ago
Please explain why B is not equal to 40? I m confused.

Deepak said:   1 decade ago
Since both return type doesn't match, how it is possible. Can any one explain?

Ramalingam said:   1 decade ago
It is very simple. From main function the value of a=20 and b=30.

Here the value of b=40 in function definition will be ignored.

Hence the option B is correct.

Post your comments here:

Your comments will be displayed after verification.