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) None of the mentioned

View Answer

Explanation:Numeric limits provides the information about the properties of arithemetic types.

2. Where does the member should be defined if it is used in the program?

a) Namespace scope

b) Character scope

c) Both a & b

d) None of the mentioned

View Answer

Explanation:The member shall still be defined in a name-space 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) None of the mentioned

View Answer

Explanation:max function in the numeric limit will return the maximum finite value for a float type.

4. What is the output of this program?

`#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) None of the mentioned

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 is the output of this program?

`#include <iostream>`

`#include <limits>`

using namespace std;

int main( )

`{`

cout << numeric_limits<short int> :: max() << endl;

`}`

b) 32423

c) 32767

d) None of the mentioned

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 is the output of this program?

`#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 is the output of this program?

`#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) All of the mentioned

View 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

`#include <iostream>`

`#include <limits>`

using namespace std;

int main( )

`{`

cout << numeric_limits<float> :: min_exponent << endl;

`}`

a) 125

b) -125

c) 123

d) None of the mentioned

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) None of the mentioned

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:None.

**Sanfoundry Global Education & Learning Series – C++ Programming Language.**

Here’s the list of Best Reference Books in C++ Programming Language.

To practice all features of C++ programming language, __here is complete set on 1000+ Multiple Choice Questions and Answers on C++__.