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

Library Functions Questions and Answers

21.

In the c library function void (*signal(int sig, void (*func)(int)))(int), which statement is true with respect to func?

Answer: A

Correct answer: func is a pointer to the function

Read the declaration outwards: void (*func)(int) makes func a pointer to a function taking an int and returning nothing - the handler to be installed. signal itself returns a pointer of the same kind, namely the previous handler, which is what makes the declaration so hard to read.

Please log in or register to report this question.

22.

If the result underflows, the function returns zero.

Answer: A

Correct answer: true

On underflow - a result too small in magnitude to be represented - a maths function returns zero, and may set errno to ERANGE. That contrasts with overflow, where it returns HUGE_VAL.

Please log in or register to report this question.

Answer: D

Correct answer: pointer to the current location

localeconv() returns a pointer to a struct lconv describing the conventions of the locale currently in force - decimal point, thousands separator, currency symbol and its placement. The structure is static, so its contents change when the locale is changed.

Please log in or register to report this question.

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.

25.

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.

26.

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.

28.

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.

30.

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.

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