Hello I have just started coding in c++, I have a question regarding returning datatypes. Suppose you have input 4 variables of the following nature
int a = 15;
double b = 30949.374;
float c = 230.47;
long d = 1000000;
and z = (a + d) * (c + b);
what would the return type of z be?
I know we can use either int, double, float and long to set the datatype of z, but what I want to know what would the resultant datatype be if all these 4 numbers are multiplied.
You always need "z" to be able to hold decimals when it is not integer multiplication. So make it a double/float.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
int main()
{
int a = 15;
double b = 30949.374;
float c = 230.47;
long d = 1000000;
auto z = (a + d) * (c + b); // Google the auto keyword c++ to find out what it does
std::cout << z << std::endl;
return 0;
}