C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 9)
9.
Which of the following statement is correct about the program given below?
#include<iostream.h>
int BixTest(int x, int y);
int BixTest(int x, int y, int z = 5);
int main()
{
cout<< BixTest(2, 4) << endl;
return 0;
}
int BixTest(int x, int y)
{
return x * y;
}
int BixTest(int x, int y, int z = 5)
{
return x * y * z;
}
Discussion:
13 comments Page 1 of 2.
Rasheed said:
7 years ago
But in function overloading its is possible right? Compiler can identify fn by using parameters. We passed 2 params here then automatically compiler know to call which one too call how it leads to error?
(2)
Dattu said:
1 decade ago
I have a small doubt, can we think that there is no "cout" that's why it cannot print any thing?
(1)
Gajala washington dc said:
4 years ago
This is actually a linking Error the compilation consists of two stages one is a compilation and another is linking so the linker will be confused to attach which function.
(1)
Nandana said:
2 years ago
To use cout and endl, you need to specify the namespace std.
std::cout << BixTest(2, 4) << std::endl;
std::cout << BixTest(2, 4) << std::endl;
(1)
Pandko said:
1 decade ago
Compiler confused which function to call so it gives compile time error.
Shriram said:
1 decade ago
There is ambiguity occur while calling the BixTest function so the compiler generate compile time error.
Anirudh said:
1 decade ago
Compiler will not be able to distinguish among the functions.
Kishor ambekar said:
1 decade ago
Compiler get confused to which function is to be called.
Kerydan said:
1 decade ago
There are two reasons why compiler generates error. Firstly, redefinition of default parameter and secondly ambiguity of BixTest call.
Ivneet said:
1 decade ago
Actually the problem is only with passing the parameter to z, if you will not pass any parameter or actual parameter there will be no error, and ambiguity rises just because of parameters not as people said above just only by bixtest.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers