Machine-translated by Google. Questions are authored in English.
Top

Library Functions Questions and Answers

11.

Which of the given function differs from the statement’errno is not necessarily set on conversion error’?

Answer: D

Correct answer: strtod()

strtod is the one that does report errors: on overflow or underflow it sets errno to ERANGE, and it also returns a pointer to the first unconverted character. The ato family - atoi, atof, atol - simply return 0 on failure and set nothing, which is why the strto functions should be preferred.

Please log in or register to report this question.

Answer: B

Correct answer: de-allocates space to which p points

free(p) returns to the heap the block that p points to, obtained earlier from malloc, calloc or realloc. It does not change p itself, which is why the pointer should be set to NULL afterwards - using it again, or freeing it twice, is undefined behaviour.

Please log in or register to report this question.

13.

Which of the given option is declared under the header file stdlib.h?

Answer: D

Correct answer: EXIT_SUCCESS

EXIT_SUCCESS and EXIT_FAILURE are defined in <stdlib.h>, alongside NULL, RAND_MAX and MB_CUR_MAX. SEEK_CUR and SEEK_END belong to <stdio.h> and CLOCKS_PER_SEC to <time.h>.

Please log in or register to report this question.

14.

MB_CUR_MAX is not defined in stdlib.h.

Answer: B

Correct answer: false

MB_CUR_MAX is defined in <stdlib.h>. It gives the maximum number of bytes in a multibyte character for the current locale, and it is needed by the conversion functions such as mbtowc.

Please log in or register to report this question.

Answer: D

Correct answer: Reposition the file pointer to the beginning of the file

rewind(fp) moves the file position indicator back to the beginning of the file and clears the error and end-of-file flags. It is equivalent to fseek(fp, 0L, SEEK_SET), except that it returns nothing and resets the flags.

Please log in or register to report this question.

16.

Input/output function prototypes and macros are defined in which header file?

Answer: C

stdio.h, which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations.

Please log in or register to report this question.

17.

Which standard library function will you use to find the last occurrence of a character in a string in C?

Answer: D

Correct answer: strrchr()

strrchr() - the extra r is for reverse - returns a pointer to the last occurrence of a character in a string, or NULL if it is absent. It is the usual way to find a file extension or the last separator in a path. The other three names do not exist; strchr() finds the first occurrence.

Please log in or register to report this question.

19.

Does there any function exist to convert the int or float to a string?

Answer: A

Correct answer: Yes

Yes - sprintf does it portably: sprintf(buf, "%d", n). The old libraries also provided itoa, ltoa and gcvt, and C11 added snprintf, which is safer because it takes the buffer size.

Please log in or register to report this question.

Answer: A

"fflush()" flush any buffered output associated with filename, which is either a file opened for writing or a shell command for redirecting output to a pipe or coprocess.

Example:
fflush(FilePointer);
fflush(NULL); flushes all streams.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Library Functions Questions and Answers || Library Functions MCQ Questions and Answers || Library Functions GK Questions and Answers || Library Functions GK MCQ Questions || Library Functions Multiple Choice Questions and Answers || Library Functions GK || GK on Library Functions || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming