C Questions and Answers – Implementation-Defined Limits – 2

«
»

This set of C Multiple Choice Questions & Answers focuses on “Implementation-Defined Limits – 2”.

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

advertisement
#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

Answer: c
Explanation: Since UCHAR_MAX (255) is greater then SCHAR_MAX (127), the output of the code shown above will be “good”.
advertisement
advertisement

2. Which of the following macros is not defined?
a) ULONG_MIN
b) LONG_MIN
c) ULONG_MAX
d) LONG_MAX
View Answer

Answer: a
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?

advertisement
#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

Answer: d
Explanation: SHRT_MIN is defined as –SHRT_MAX – 1, hence the output of the code shown above will be zero.
advertisement

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

Answer: b
Explanation: Since the minimum value of CHAR_MIN is equal to -128, hence the output of the code shown above is -128.
advertisement

5. _____________ defines the minimum value for a short integer.
a) SHINT_MIN
b) SHRT_MIN
c) SINT_MIN
d) SHORT_MIN
View Answer

Answer: b
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

Answer: a
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

Answer: c
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

Answer: b
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

Answer: d
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

Answer: c
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.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
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 | Youtube | Instagram | Facebook | Twitter