This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Implementation-Defined Limits – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What will be the output of the following C code?
#include<stdio.h> #include<limits.h> main() { if(UCHAR_MAX<=SCHAR_MAX) printf("hello"); else printf("good"); }
a) error
b) hello
c) good
d) hellogood
View Answer
Explanation: 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
View Answer
Explanation: 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<stdio.h> #include<limits.h> main() { int d; d=SHRT_MAX + SHRT_MIN+1; printf("%d",d); }
a) -1
b) error
c) 1
d) 0
View Answer
Explanation: 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<stdio.h> #include<limits.h> main() { int d; d=CHAR_MIN; printf("%d",d); }
a) 0
b) -128
c) error
d) -1
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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<stdio.h> #include<limits.h> #include<float.h> main() { short int d; d=INT_MAX + FLT_MAX; printf("%d",d); }
a) error
b) 6000
c) 327
d) -328
View Answer
Explanation: 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
View Answer
Explanation: 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<stdio.h> #include<limits.h> int main() { int d; d=CHAR_MAX; printf("%c",d); }
a) Error
b) 127
c) Alphabet corresponding to the value 127
d) Junk value
View Answer
Explanation: 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
View Answer
Explanation: 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.
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 BCA MCQs
- Practice Computer Science MCQs
- Check Computer Science Books
- Apply for Computer Science Internship
- Check C Books