+ 1
Float x=5; int y=x; auto v=x-y;
what is the data type of v(int or float)?
6 Respuestas
+ 9
Data Type of v is float.
##
This is a result of the pattern called usual arithmetic conversions that converts operands in order to yield result in a common type :
if either operand is float, the other shall be converted to float.
the only case where the type of result is int, is when both operands are int.
+ 1
thank u..😁👍
+ 1
Tip:
If you are not sure what data type something is here is a trick
template<typename T>
class NonExistingClass;
int main()
{
float x = 5;
int y = x;
auto v = x - y;
NonExistingClass<decltype(v)> a;
}
You declare a non existing template class when you attempt the run this code the compiler should give you an error message along the lines of:
error: aggregate 'NonExistingClass<float> a' has incomplete type and cannot be defined.
and now you know v is a float :)
0
float is decimal value like 1.2,2.3 etcc
how could u give integer value in float
0
that a PrO TriCK Dude.....
- 1
1) declairing float x=5
a) printing %f x--> 5.00000
b) printing %d x---> 0
2)declaring int x= 5
a) printing %f a---> wont run in compilers....some compiler will show errors...some will compile but wont run