MCQs
The char has lesser bytes than int and int has lesser bytes than double whereas int and float
can potentially have same sizes.
0.5f results in 0.5 to be stored in floating point representations.
Output:
$ g++ float.cpp
$ a.out
equal
None.
The value 123 is printed because of its precision.
$ g++ float.cpp
$ a.out
123
The double had to truncate the approximation due to it’s limited memory, which resulted in a number
that is not exactly 0.1.
Output:
$ g++ float2.out
$ a.out
0.10000000000000001
To make a floating point literal, we should attach a suffix of ‘f’ or ‘F’ and there should not be any
blank space.
None.
Float store floating point numbers with 8 place accuracy and requires 4 bytes of Memory. Double
has 16 place accuracy having size of 8 bytes.
Output:
$ g++ float3.cpp
$ a.out
harvard
Floating point types occur in only three sizes-float, long double and double.
Float for single precision, double for double precision and long double for extended precision.