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

Library Functions Questions and Answers

Answer: B

Correct answer: va_start, va_end and va_arg

va_start must be called before either of the others: it initialises the va_list from the last named parameter. va_arg then fetches the arguments one at a time, and va_end tidies up before the function returns.

Please log in or register to report this question.

Answer: A

Correct answer: flushes all streams and specified streams

fflush(fp) writes out the buffer of one stream; fflush(NULL) flushes every output stream. It matters because output is buffered: without a flush, text may still be sitting in memory when a program crashes. (fflush on an input stream is undefined behaviour, despite being widely misused.)

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.

34.

Which of the following library functions is used to read location dependent information?

Answer: B

Correct answer: localeconv()

localeconv() returns a pointer to a struct lconv describing the current locale’s numeric and monetary conventions - the decimal point, the thousands separator, the currency symbol and where it goes. localtime() converts a time and has nothing to do with locales in this sense.

Please log in or register to report this question.

35.

Determine Output:

#include <stdio.h>
#define a 10
void main()
{
      #define a 50
      printf("%d", a);
}

 

Answer: A

Correct answer: 50

The preprocessor works on the text in order and takes no notice of braces, so the second #define is in force by the time the printf line is expanded - and the program prints 50. Redefining a macro to a different value without an intervening #undef is not strictly conforming, so expect a warning.

Please log in or register to report this question.

36.

The header file assert.h of the C Standard Library defines ________macro.

Answer: D

Correct answer: assert

<assert.h> defines exactly one thing: the assert macro, which tests a condition and, if it is false, prints the expression, the file and the line and calls abort(). Defining NDEBUG before the include turns every assertion into nothing, which is how they are removed from a release build.

Please log in or register to report this question.

37.

Data written into a file using fwrite() can be read back using fscanf()

Answer: B

Correct answer: False

fwrite writes data in its binary representation, while fscanf reads formatted text. The two do not match: an int written by fwrite is four raw bytes, not the digits %d expects. Data written with fwrite must be read back with fread.

Please log in or register to report this question.

38.

The itoa function can convert an integer in decimal, octal or hexadecimal form to a string.

Answer: A

Correct answer: Yes

itoa(value, buffer, base) takes a base as its third argument, so it will produce the decimal, octal, hexadecimal or binary representation. It is not a standard C function - it belongs to the Turbo C and Microsoft libraries - and sprintf is the portable substitute.

Please log in or register to report this question.

39.

The function strlen() includes the terminating null character in the length it returns.

Answer: B

Correct answer: False

strlen() counts only the characters before the terminating null, so strlen("abc") is 3. The array holding that string nevertheless needs 4 bytes, which is why sizeof and strlen give different answers.

Please log in or register to report this question.

Answer: B

Correct answer: Convert floating-point number to a string

gcvt() converts a floating-point number to a string, in the shorter of fixed and exponential notation for the requested number of significant digits. It is a non-standard function of the old Unix and Turbo C libraries; sprintf is the portable way to do the same thing.

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