# Argument Coercion in C/C++?

CC++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

Best Seller

66 Lectures 5.5 hours

Here we will see about the argument coercion in C or C++. The Argument Coercion is one technique by which the compiler can implicitly convert the arguments from one type to another type. It follows argument promotion rule. If one argument is lower datatype, that can be converted into higher datatypes, but the reverse is not true. The reason is if one higher datatype is converted into a lower datatype, it may loss some data.

Let us see one pyramid that can express how the implicit conversion takes place.

## Example

Live Demo

#include<iostream>
using namespace std;
double myAdd(double a, double b){
return a+b;
}
main() {
cout << "double data add: " << myAdd(5.3, 6.9) << endl;
cout << "integer data add: " << myAdd(6, 5) << endl;
}

## Output

double data add: 12.2
integer data add: 11
Updated on 30-Jul-2019 22:30:26

Advertisements