C Questions and Answers – General Utilities – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “General Utilities – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. _______variable type defined in the header stdlib.h is an integer type of the size of a wide character constant.
a) size_t
b) wchar_t
c) div_t
d) ldiv_t
View Answer

Answer: b
Explanation: wchar_t
This is an integer type of the size of a wide character constant defined under the header stdlib.h .

2. Which of the following is the correct description of EXIT_FAILURE?
a) This is the value for the exit function to return in case of failure
b) This is the value for the exit function to terminate the program
c) This is the value for the exit function to return in case of success
d) This is the value for the exit function to return in case it is the maximum value
View Answer

Answer: a
Explanation: The macros defined is EXIT-FAILURE which expand to integral expressions that may be used as the argument to the exit function to return unsuccessful.
advertisement
advertisement

3. RAND_MAX macro is the maximum value returned by the rand function.
a) true
b) false
View Answer

Answer: a
Explanation: RAND_MAX is the macro which expands to an integral constant expression, the value of which is the maximum value returned by the rand function.

4. Which of the given function converts the string pointed to, by the argument str to a floating-point number?
a) atof(const char *str)
b) strtod(const char *str, char **endptr)
c) atoi(const char *str)
d) atol(const char *str)
View Answer

Answer: a
Explanation: The atof function converts the initial portion of the string pointed to by str to double representation. Except for the behavior on the error, it is equivalent to strtod (nptr, (char **)NULL).

5. The_______function converts the initial portion of the string pointed to by, to int representation.
a) atof()
b) atoi()
c) strtod()
d) atol()
View Answer

Answer: b
Explanation: int atoi(const char *str); The C library function int atoi(const char *str) converts the string argument str to an integer (type int).

6. atol(const char *str) Converts the string pointed to, by the argument str.
a) to a long integer
b) to a integer
c) to a floating point number
d) to a unsigned long integer
View Answer

Answer: a
Explanation: long int atol(conat char *str);
The atol() function converts the initial portion of the string pointed to by str to long int representation. Except for the behavior on error, it is equivalent to strtol (nptr, (char **)NULL, 10).
advertisement

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

char str[20];
str= "123546"; res= atof(str);
printf("String value = %s, Float value = %f\n", str, res);

a) String value = 123546, Float value = 123546.0
b) String value = 123546 , Float value = 123546.000000
c) String value = 123546 , Float value = 0.000000
d) String value = 123546 , Float value = 123546.000
View Answer

Answer: b
Explanation: atof() function returns the converted floating point number as a double value.

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

advertisement
char str[]; 
strcpy(str, "Hello"); 
res = atof(str);
printf("String value = %s, Float value = %f\n", str, res);

a) String value = Hello, Float value = 0.000000
b) String value = Hello, Float value = 0
c) String value = “Hello” , Float value = 0.000000
d) String value = “Hello” , Float value = 0
View Answer

Answer: a
Explanation: atof() function returns the converted floating point number as a double value. If no valid conversion could be performed, it returns zero (0.0).

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

char str[20]; 
strcpy(str, "123456"); 
res = atoi(str);
printf("%s  %d\n", str, res);

a) 123456 0
b) 123456 0.0
c) 123456 123456
d) 123456 123456.0
View Answer

Answer: c
Explanation: atoi() function returns the converted integral number as an int value.

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

char str[] ;  
strcpy(str, "Hello"); 
res = atoi(str);
printf(" %s  %d\n", str, res);

a) Hello 0.000000
b) “Hello” 0.000000
c) Hello 0
d) “Hello” 0
View Answer

Answer: c
Explanation: atoi() function returns the converted integral number as an int value. If no valid conversion could be performed, it returns zero.

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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). 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!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.