Argument coercion is a feature of function prototypes by which the compiler implicitly converts the datatype of the arguments passed during the function call to match the datatype in the definition of the function.
It follows Argument promotion rules. Therefore a lower datatype maybe converted into a higher datatype but vice-versa is not true. This is because when a higher datatype is converted to a lower datatype it can result into loss or truncation of data.
The Promotion hierarchy for fundamental datatypes in C++ is:
Example: Take for Example the code given below consists of an add function that expects double arguments. But even when integer arguments are passed it works correctly. In case long double arguments are passed the code will give an error.
- Variable Length Argument in C
- Difference between Argument and Parameter in C/C++ with Examples
- C function argument and return values
- Why copy constructor argument should be const in C++?
- Modulo Operator (%) in C/C++ with Examples
- fpclassify() method in C/C++ with Examples
- Operator Overloading '<<' and '>>' operator in a linked list class
- How to find the Entry with largest Value in a C++ Map
- getch() function in C with Examples
- Visibility Modes in C++ with Examples
- Chain of Pointers in C with Examples
- Pointer Expressions in C with Examples
- Speed up Code executions with help of Pragma in C/C++
- Vector of Vectors in C++ STL with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.