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

Library Functions Questions and Answers

Answer: B

Correct answer: The atexit() function is used to return zero if the registration succeeds, nonzero if it fails

atexit() registers a function to be called when the program terminates normally, and returns zero on success. Registered functions run in the reverse order of registration, and at least 32 must be allowed. They are not called if the program ends through abort().

Please log in or register to report this question.

22.

If the result overflows, the function returns the value of the macro HUGE_VAL, carrying the same sign except for the_________ function as the correct value of the function.

Answer: D

Correct answer: tan

On overflow a maths function returns HUGE_VAL with the same sign as the true result - but tan is the exception. Its overflow happens at a pole, where the function runs to \(+\infty\) on one side and \(-\infty\) on the other, so an argument only slightly to one side or the other of \(\pi/2\) gives opposite signs. With the argument itself known only approximately, the sign cannot be relied on.

Please log in or register to report this question.

23.

What will be the output of the program?

#include <stdio.h>

int main()
{
    int i;
    i = printf("How r u\n");
    i = printf("%d\n", i);
    printf("%d\n", i);
    return 0;
}

 

Answer: B

Correct answer: How r u 8 2

printf returns the number of characters written. The first call writes How r u and a newline - 8 characters - so i becomes 8. The second prints 8 and a newline, which is 2 characters, so i becomes 2. The third prints that 2.

Please log in or register to report this question.

Answer: D

Correct answer: returns a random number generator with a random value based on time

randomize() seeds the random number generator from the system clock, so that a program produces a different sequence on each run. Without it, rand() starts from the same seed every time and repeats the same numbers - which is convenient for debugging and useless for a game.

Please log in or register to report this question.

25.

Which of the following macros is defined under the header limits.h?

Answer: B

Correct answer: USHRT_MAX

USHRT_MAX - the largest value an unsigned short can hold - is in <limits.h>, along with CHAR_BIT, INT_MAX and the rest of the integer limits. The floating-point limits, DBL_MAX, FLT_ROUNDS and DECIMAL_DIG, are in <float.h>.

Please log in or register to report this question.

Answer: B

int system(const char *command) function is used to pass the command name or the program name specified by command to the host environment to be executed by the command processor and returns after the command has been completed.

Please log in or register to report this question.

27.

HUGE_VAL macro is used when the output of the function may not be ___________

Answer: A

Correct answer: floating point numbers

HUGE_VAL is what a maths function returns on overflow - when the true result is too large to be represented as a double. It is returned with errno set to ERANGE, which is how the caller can tell an overflow from a legitimate large value.

Please log in or register to report this question.

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.

Loading…
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