Here is a listing of C++ questions and puzzles on “Numeric Limits” along with answers, explanations and/or solutions:
1. To which type does the numeric limits are suitable?
a) Character types
b) Mixed type
c) Arithmetic types
d) Relational types
View Answer
Explanation: Numeric limits provides the information about the properties of arithmetic types.
2. Where does the member should be defined if it is used in the program?
a) Namespace scope
b) Character scope
c) Namespace & Character scope
d) Directional scope
View Answer
Explanation: The member shall still be defined in a namespace scope if it is used in the program.
3. What will the max function in the numeric limit will return for type float?
a) Maximum finite value for a float type
b) Maximum finite value
c) Minimum finite value
d) Minimum float value
View Answer
Explanation: Max function in the numeric limit will return the maximum finite value for a float type.
4. What will be the output of the following C++ code?
#include <iostream>
#include <limits>
using namespace std;
int main ()
{
cout << boolalpha;
cout << numeric_limits<int> :: has_infinity << '\n';
return 0;
}
a) 53234
b) false
c) true
d) 32564
View Answer
Explanation: In this program, We are checking whether the integer has limit or not by using has_infinity function.
Output:
$ g++ num.cpp $ a.out false
5. What will be the output of the following C++ code?
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<short int> :: max() << endl;
}
a) 53723
b) 32423
c) 32767
d) 4668
View Answer
Explanation: In this program, We are finding the max range for short int by using max function.
Output:
$ g++ num1.cpp $ a.out 32767
6. What will be the output of the following C++ code?
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float> :: is_exact;
cout << numeric_limits<double> :: is_exact;
cout << numeric_limits<long int> :: is_exact;
cout << numeric_limits<unsigned char> :: is_exact;
}
a) 0010
b) 0012
c) 1100
d) 0011
View Answer
Explanation: In this program, We are finding whether the types are free of rounding errors by using the function is_exact.
Output:
$ g++ num2.cpp $ a.out 0011
7. What will be the output of the following C++ code?
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float> :: digits10 << endl;
cout << numeric_limits<double> :: digits10 << endl;
float f = 99999999;
cout.precision ( 10 );
cout << f << endl;
}
a) 6
b) 15
c) 100000000
d)
6 15 100000000View Answer
Explanation: In this program, We are finding the number of decimal points that the type can represent without loss of precision.
Output:
$ g++ num3.cpp $ a.out 6 15 100000000
8. What will be the output of the following C++ code?
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float> :: min_exponent << endl;
}
a) 125
b) -125
c) 123
d) 521
View Answer
Explanation: In this program, We are finding the minimum radix of a type by using min_exponent function.
Output:
$ g++ num4.cpp $ a.out -125
9. Which header file is used for the numeric limits in C++?
a) <iostream>
b) <limits>
c) <number>
d) <digit>
View Answer
Explanation: <limits> header file will be used for numeric limits in C++.
10. Pick out the incorrect static function member in numeric limits.
a) denorm_min
b) digits
c) infinity
d) max_finite
View Answer
Explanation: max_finite is the incorrect static function member in numeric limits.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Practice Programming MCQs
- Apply for Computer Science Internship
- Apply for C++ Internship
- Check Computer Science Books
- Check C++ Books