C Questions and Answers – Implementation-Defined Limits – 1

«
»

This set of C MCQs focuses on “Implementation-Defined Limits – 1”.

1. The maximum value of a signed char is not the same as the maximum value of an unsigned char.
a) True
b) False
View Answer

Answer: a
Explanation: The maximum value of a signed char is 127 and that the maximum value of an unsigned char is 255. Thus it is clear that the maximum value of a signed char is not the same as the maximum value of an unsigned char.
advertisement

2. What will be the output of the following C code?

#include <stdio.h>
#include <limits.h>
int main() 
{
    printf("The minimum value of LONG = %lf\n", LONG_MIN);
    return 0;
}

a) -2147483648 (The minimum value of LONG)
b) 0.000000
c) 0
d) error
View Answer

Answer: b
Explanation: Since the format specifier %lf is used, 0.000000 is given as the output. If we want the output to be the minimum value of LONG, we should use the format specifier %ld is used.

3. The macro __________ defines the number of bits in a byte, which is equal to _______
a) CHAR_BIT, 4
b) CHAR_BYTE, 8
c) CHAR_BIT, 8
d) CHAR_BYTE, 4
View Answer

Answer: c
Explanation: The macro CHAR_BIT defines the number of bits in a byte, which is equal to 8.

4. What will be the output of the following C code?

advertisement
#include<stdio.h>
#include<limits.h>
main()
{
    printf("%f",FLT_MIN);
}

a) Minimum negative value of float
b) Maximum positive value of float
c) Error
d) Minimum positive value of float
View Answer

Answer: c
Explanation: The macro FLT_MIN is not defined under the header file limits.h. To use any macro relate to a floating point value or a double value, we should include the header file float.h. Since this header file is not included in the code shown above, it will result in an error.

5. The macro MB_LEN_MAX is used to find _________
a) Maximum number of bytes in a multi-byte character
b) Whether the given function is valid or not
c) The maximum time taken for the execution of a particular function
d) Maximum number of bits in a multi-byte character
View Answer

Answer: a
Explanation: The macro MB_LEN_MAX is defined under the header file limits.h and is used to find the maximum number of bytes in a multi-byte character.

6. The value of CHAR_MAX will be equal to SCHAR_MAX when _________
a) char represents positive value
b) char represents value equal to 0
c) char represents negative value
d) char represents an exponential value
View Answer

Answer: c
Explanation: The macro CHAR_MAX defines the maximum value for type char and its value is equal to SCHAR_MAX is char represents negative value, otherwise UCHAR_MAX.

7. What will be the output of the following C code, given that the maximum value of signed char is 127 and that of unsigned char is 255.

#include<stdio.h>
#include<limits.h>
#define SCHAR_MAX
main()
{
    printf("%d",SCHAR_MAX+1);
}

a) 256
b) Error
c) 1
d) 128
View Answer

Answer: c
Explanation: The output of the code shown above will be equal to 1. This is because we have used the macro define to define a variable known as SCHAR_MAX (assigned a value of zero). Had this line not been a part of the above code, the output would be 128.
advertisement

8. The macro which is used to find the maximum value of an unsigned integer is _________
a) UNINT_MAX
b) UNSINT_MAX
c) UINT_MAX
d) UNIT_MAX
View Answer

Answer: c
Explanation: The macro which is used to define the maximum value on an unsigned integer is: UINT_MAX. To find the maximum value on a signed integer, we use the macro: SINT_MAX.

9. To find the maximum value of an object of type unsigned long long int, we use the macro _________
a) ULINT_MAX
b) ULLINT_MAX
c) ULONG_MAX
d) ULLONG_MAX
View Answer

Answer: d
Explanation: The macro ULLONG_MAX is used to find the maximum value of unsigned long long int type. The macro ULONG_MAX is used to find the maximum value of unsigned long type.

10. Which of the following macros is defined under the header limits.h?
a) FLT_ROUNDS
b) USHRT_MAX
c) DBL_MAX
d) DECIMAL_DIG
View Answer

Answer: b
Explanation: the macros FLT_ROUNDS, DBL_MAX and DECIMAL_DIG are defined under the header float.h. The macro USHRT_MAX is defined under the header limits.h.

Sanfoundry Global Education & Learning Series – C Programming Language.

advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn