966 views

Which one of the following is correct for overloaded functions in $C++$?

1. Compiler sets up a separate function for every definition of function.
2. Compiler does not set up a separate function for every definition of function.
3. Overloaded functions cannot handle different types of objects.
4. Overloaded functions cannot have same number of arguments.

### 1 comment

According to the overloading‘s definition function the same name with different parameter,

For each overload function complier treat as a new function so option A is correct.

Now See option D

Can two overloaded functions hold the same number of parameters?

Ans is Yes but a different type means example

fun()

fun(int a)

fun(char c)

Option D is Wrong

When you call an overloaded function or operator, the compiler determines the most appropriate definition to use by comparing the argument types you used to call the function or operator with the parameter types specified in the definitions. The process of selecting the most appropriate overloaded function or operator is called overload resolution.

Ans: (A)

### 1 comment

just take a smaal example:-

int sum(int ,int);

int sum(float,float,float);

int main()

{

float x=5.5,y=6.5;

float m= sum(x,y);

}

now my doubt is when i passed x,y to sum ;x,y are of float type but there is no fn def which takes 2 float parameters;

therefore x,y will be degraded to int and int sum will be returned!

so no fn def is there for

sum(float,float)

but when needed it is degraded to sum(int,int)

hence,shouldn't the option be (B).

by

1
1,895 views
2
741 views
3