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

Library Functions Questions and Answers

31.

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.

32.

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.

33.

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.

34.

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.

35.

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.

36.

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.

38.

Will the program outputs "IndiaBIX.com"?

#include <stdio.h>
#include <string.h>

int main()
{
    char str1[] = "IndiaBIX.com";
    char str2[20];
    strncpy(str2, str1, 8);
    printf("%s", str2);
    return 0;
}

 

Answer: B

No. It will print something like 'IndiaBIX(some garbage values here)' .

Because after copying the first 8 characters of source string into target string strncpy() doesn't terminate the target string with a '\0'. So it may print some garbage values along with IndiaBIX.

Please log in or register to report this question.

39.

If the two strings are found to be unequal then strcmp returns difference between the first non-matching pair of characters.

Answer: A

Correct answer: True

strcmp compares character by character and, at the first difference, returns the difference between those two characters - negative, zero or positive. Only the sign is guaranteed by the standard, so code should test < 0 or > 0 rather than expect a particular number.

Please log in or register to report this question.

40.

The assert macro returns __________ value.

Answer: D

Correct answer: no

assert is a void macro: it returns nothing. If the condition holds it does nothing at all; if it fails it prints the expression, the file and the line and calls abort(). So it can never appear where a value is wanted.

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