ICSE Class 10 Computer Applications Question 26 of 43

User-Defined Methods — Question 26

Back to all questions
26
Question

Question 24

How does the use of constant suffixes help avoid ambiguity when an overloaded function is called ?

Answer

Sometimes, there might be ambiguity between float and double values or int or long values.

For instance, if you want to invoke the function with following declaration: void prnsqr(double d) with the value 1.24. This value may also be assumed to be float as well as double.

To avoid such ambiguity, we can use constant suffixes (F, L, D, etc.) to distinguish between such values as these greatly help in indicating which overloaded function should be called.

An ordinary floating constant (312.32) has the double type, while adding the F suffix (312.32 F) makes it a float. The suffix L (312.32L) makes it a long double. Similarly, suffix D or d makes it a double.