C MCQs on “General Utilities – 1”.
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
Answer: b
Clarification: 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
Answer: a
Clarification: 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.
3. RAND_MAX macro is the maximum value returned by the rand function.
a) true
b) false
Answer: a
Clarification: 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)
Answer: a
Clarification: 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()
Answer: b
Clarification: 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
Answer: a
Clarification: 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).
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 = %fn", 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
Answer: b
Clarification: atof() function returns the converted floating point number as a double value.
8. What will be the output of the following C code?
char str[]; strcpy(str, "Hello"); res = atof(str); printf("String value = %s, Float value = %fn", 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
Answer: a
Clarification: 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 %dn", str, res);
a) 123456 0
b) 123456 0.0
c) 123456 123456
d) 123456 123456.0
Answer: c
Clarification: 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 %dn", str, res);
a) Hello 0.000000
b) “Hello” 0.000000
c) Hello 0
d) “Hello” 0
Answer: c
Clarification: atoi() function returns the converted integral number as an int value. If no valid conversion could be performed, it returns zero.
