C Multiple Choice Questions & Answers on “Implementation-Defined Limits – 2”.
1. What will be the output of the following C code?
#include#include main() { if(UCHAR_MAX<=SCHAR_MAX) printf("hello"); else printf("good"); }
a) error
b) hello
c) good
d) hellogood
Answer: c
Clarification: Since UCHAR_MAX (255) is greater then SCHAR_MAX (127), the output of the code shown above will be “good”.
2. Which of the following macros is not defined?
a) ULONG_MIN
b) LONG_MIN
c) ULONG_MAX
d) LONG_MAX
Answer: a
Clarification: The macro ULONG_MIN is not defined whereas the macros LONG_MIN, ULONG_MAX and LONG_MAX are all defined in the header file limits.h.
3. Given that the value of SHRT_MAX is equal to 32767 and that of SHRT_MIN is equal to -32768, What will be the output of the following C code?
#include#include main() { int d; d=SHRT_MAX + SHRT_MIN+1; printf("%d",d); }
a) -1
b) error
c) 1
d) 0
Answer: d
Clarification: SHRT_MIN is defined as –SHRT_MAX – 1, hence the output of the code shown above will be zero.
4. What will be the output of the following C code?
#include#include main() { int d; d=CHAR_MIN; printf("%d",d); }
a) 0
b) -128
c) error
d) -1
Answer: b
Clarification: Since the minimum value of CHAR_MIN is equal to -128, hence the output of the code shown above is -128.
5. _____________ defines the minimum value for a short integer.
a) SHINT_MIN
b) SHRT_MIN
c) SINT_MIN
d) SHORT_MIN
Answer: b
Clarification: to define the minimum value for a short integer, we use the macro SHRT_MIN (defined under the header file limits.h).
6. The macro definition of INT_MIN is ____________
a) –INT_MAX – 1
b) INT_MAX – 1
c) –INT_MAX + 1
d) INT_MAX + 1
Answer: a
Clarification: The macro definition of INT_MIN is –INT_MAX – 1.
7. What will be the output of the following C code?
Maximum value of int = 1000 Maximum value of float = 5000 Maximum value of short int = 327 Minimum value of short int = -328 #include#include #include main() { short int d; d=INT_MAX + FLT_MAX; printf("%d",d); }
a) error
b) 6000
c) 327
d) -328
Answer: c
Clarification: Since the data type in which we store the result of the expression INT_MAX + FLT_MAX is of the type short int, the output of the code shown above will be the maximum of short int. Hence the output is 327.
8. The macros defined under the header file limits.h are not defined under any other header file.
a) False
b) True
Answer: b
Clarification: Macros such as INT_MAX, ULONG_MAX etc which are defined under the header file limits.h are not defined under any other header file.
9. What will be the output of the following C code if the value of UCHAR_MAX is 127?
#include#include int main() { int d; d=CHAR_MAX; printf("%c",d); }
a) Error
b) 127
c) Alphabet corresponding to the value 127
d) Junk value
Answer: d
Clarification: The output of the code shown above will be some junk value. This is because we have used the format specifier %c in the print statement. Had we used the format specifier %d, the output would have been 127 (maximum value of char).
10. The minimum value of CHAR_BIT is equal to ________
a) 2
b) 4
c) 8
d) 16
Answer: c
Clarification: The minimum value of CHAR_BIT is equal to 8. This is because the macro CHAR_BIT returns the maximum number of bits in a char object. 1 byte contains 8 bits. Hence the value of CHAR_BIT cannot be less than 8.
