- Exercise

Let's test your knowledge of automatic type deduction with this exercise.

We'll cover the following

Exercise 1 #

Let’s get used to the rules of implicit type casts by arithmetic operations. Call the add function that we studied earlier with different arguments and ask for the return type of each operation with typeid.

Here are a few examples:

std::cout << typeid( add(1, false) ).name() << std::endl; 
std::cout << typeid( add('a', 1) ).name() << std::endl; 
std::cout << typeid( add(false, false) ).name() << std::endl; 
std::cout << typeid( add(true, 3.14) ).name() << std::endl; 
std::cout << typeid( add(1, 4.0) ).name() << std::endl;

We can try out our work in the code widget below:

Get hands-on with 1400+ tech skills courses.