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

Library Functions Questions and Answers

Answer: A

Correct answer: Maximum number of bytes in a multi-byte character

MB_LEN_MAX, in <limits.h>, is the largest number of bytes any multibyte character can occupy in any supported locale - so a buffer of that size is always big enough. Its companion MB_CUR_MAX, in <stdlib.h>, gives the maximum for the locale currently in force.

Please log in or register to report this question.

72.

Which macro is used in the setlocale() function?

Answer: C

Correct answer: LC_MESSAGES

The category macros passed to setlocale are LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME and, in POSIX, LC_MESSAGES. Each names one aspect of the locale, so that a program can, say, take its number formatting from one locale and its messages from another.

Please log in or register to report this question.

Answer: A

Correct answer: void longjmp(jmp_buf environment, int value)

longjmp takes the jmp_buf saved by setjmp and an int, and restores the saved environment - whereupon setjmp appears to return that value. A value of 0 is silently changed to 1, so that the caller can always distinguish a longjmp arrival from the original call.

Please log in or register to report this question.

74.

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.

75.

The library function clock() returns the number of _________ elapsed since the start of the program.

Answer: B

Correct answer: clock ticks

clock() returns processor time in implementation-defined units, clock ticks. To get seconds, divide by CLOCKS_PER_SEC. Note that it measures processor time used, not elapsed wall-clock time, so a program that spends its time waiting shows very little.

Please log in or register to report this question.

76.

What will be the output of the program?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char *i = "55.555";
    int result1 = 10;
    float result2 = 11.111;
    result1 = result1+atoi(i);
    result2 = result2+atof(i);
    printf("%d, %f", result1, result2);
    return 0;
}

 

Answer: C

Function atoi() converts the string to integer.
Function atof() converts the string to float.

result1 = result1+atoi(i);
Here result1 = 10 + atoi(55.555);
result1 = 10 + 55;
result1 = 65;

result2 = result2+atof(i);
Here result2 = 11.111 + atof(55.555);
result2 = 11.111 + 55.555000;
result2 = 66.666000;
So the output is "65, 66.666000" .

Please log in or register to report this question.

77.

The _______ macro shall be invoked before any access to the unnamed arguments.

Answer: D

Correct answer: va_start

va_start must be called first: it initialises the va_list, using the last named parameter to work out where the unnamed ones begin. Only then may va_arg fetch them, and va_end must be called before the function returns.

Please log in or register to report this question.

78.

Which function returns a pseudo-random integer?

Answer: B

Correct answer: rand()

rand() returns a pseudo-random integer between 0 and RAND_MAX. srand() sets the seed and returns nothing; malloc allocates memory.

Please log in or register to report this question.

79.

Can you use the fprintf() to display the output on the screen?

Answer: A

Correct answer: Yes

fprintf writes to whatever stream it is given, and stdout is a stream like any other - so fprintf(stdout, "...") prints to the screen, exactly as printf does. Indeed printf(...) is defined as fprintf(stdout, ...).

Please log in or register to report this question.

80.

Which macro can be used to detect and report exceptional conditions?

Answer: C

Correct answer: assert

assert(expr) tests a condition that ought to be true and, if it is not, reports the expression, file and line and aborts. It is for catching programming errors during development, not for handling conditions a correct program might meet - and defining NDEBUG removes every assertion from the build.

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