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

Library Functions Questions and Answers

81.

What will be the output of the program?

#include <stdio.h>

int main()
{
    int i;
    i = scanf("%d %d", &i, &i);
    printf("%d\n", i);
    return 0;
}

 

Answer: B

Correct answer: 2

scanf returns the number of items successfully converted and assigned, not the values themselves. Two conversions succeed here, so it returns 2, and that is what is stored in i and printed - overwriting whatever the two conversions had put there.

Please log in or register to report this question.

82.

scanf() or atoi() function can be used to convert a string like "436" in to integer.

Answer: A

Correct answer: Yes

Both work. atoi("436") converts the string directly, and sscanf(str, "%d", &n) does the same with error reporting. strtol is better than either, since it distinguishes a genuine 0 from a failed conversion.

Please log in or register to report this question.

83.

A non-zero value is returned, if setjmp() returns from a longjmp() function call.

Answer: B

Correct answer: true

setjmp returns 0 when it is called directly to save the environment, and a non-zero value when control arrives there from a longjmp - the value longjmp was given. Testing the return value is how the code distinguishes the two arrivals.

Please log in or register to report this question.

84.

Point out the error in the following program.

#include <stdio.h>

int main()
{
    char str[] = "IndiaBIX";
    printf("%.#s %2s", str, str);
    return 0;
}

 

Answer: D

Correct answer: No error

There is no error. %.#s and %2s are not the specifiers the author probably intended, but printf is not obliged to reject them - the format string is parsed at run time, and undefined or unrecognised conversions do not stop the program compiling. The array declaration is perfectly ordinary.

Please log in or register to report this question.

85.

Which function will return the quotient and remainder on division of numerator with denominator?

Answer: A

Correct answer: div()

div(num, den) returns a div_t structure containing both the quotient (.quot) and the remainder (.rem). Getting both from one call is cheaper than a separate / and %, and the truncation behaviour is guaranteed. div_t is the type, not a function.

Please log in or register to report this question.

86.

Which function returns the number of bytes in the multibyte character pointed to by its argument?

Answer: C

Correct answer: mblen()

mblen() returns the number of bytes in the multibyte character its argument points to. getenv reads environment variables, and bsearch and qsort search and sort arrays.

Please log in or register to report this question.

87.

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

Correct answer: reports a synchronous signal

raise(sig) sends a signal to the running program itself, so it arrives synchronously at a known point in the code. Installing a handler is the job of signal(); asynchronous signals come from outside the program.

Please log in or register to report this question.

89.

Select the macro that affects the information provided by localeconv function.

Answer: C

Correct answer: LC_NUMERIC

localeconv() reports the numeric and monetary conventions, so it is governed by LC_NUMERIC - decimal point and thousands separator - and by LC_MONETARY for the currency fields. LC_COLLATE affects string comparison and LC_CTYPE character classification; neither shows up in the struct lconv.

Please log in or register to report this question.

90.

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.

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