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;
}
Discussion:
5 comments Page 1 of 1.
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.
Here the value of b=40 in function definition will be ignored.
Hence the option B is correct.
RAJ said:
10 years ago
Its simple as answer is B since we pass as call the function value is 20 & 30 respectively.
Deepak said:
1 decade ago
Since both return type doesn't match, how it is possible. Can any one explain?
Swati said:
1 decade ago
Please explain why B is not equal to 40? I m confused.
Adithya.R said:
8 years ago
Given a=20 and b= 30.
Therefore answer is a=20 b=30.
Therefore answer is a=20 b=30.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers