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

Library Functions Questions and Answers

61.

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.

Answer: D

Correct answer: All of the above

The preprocessor does all three: file inclusion through #include, macro expansion through #define, and conditional compilation through #if and its relatives. All of it happens on the text before the compiler proper sees anything.

Please log in or register to report this question.

Answer: C

Correct answer: has # as the first character

A directive is recognised by the #, which must be the first non-blank character on its own line. It may be indented, but nothing else may precede it on that line, and it must not be placed after other code. Nor need it come before the first executable statement - directives may appear anywhere in the file.

Please log in or register to report this question.

64.

Which of the following is defined under the header file time.h?

Answer: D

Correct answer: NULL

NULL is one of the few names defined in several headers at once, <time.h> among them - so a program gets it from whichever it happens to include. fabs belongs to <math.h>, iscntrl to <ctype.h> and the string functions to <string.h>.

Please log in or register to report this question.

65.

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.

Answer: A

Correct answer: it returns a string representing the local time

ctime() takes a time_t and returns a printable string in local time, of the form Wed Jun 30 21:49:08 2021\n. It is asctime(localtime(t)) in one call. The string is in a static buffer, so it is overwritten by the next call.

Please log in or register to report this question.

68.

The mbstowcs() function is used to return the number of array elements modified, not including a terminating zero code, if any.

Answer: A

Correct answer: true

mbstowcs() converts a multibyte string to a wide-character string and returns the number of wide characters written, not counting the terminating null - or (size_t)-1 if it meets an invalid multibyte sequence.

Please log in or register to report this question.

69.

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: A

Correct answer: first byte of multibyte character

mblen(s, n) examines the multibyte character beginning at s - the pointer must therefore be at its first byte, since the length can only be determined from there. It returns how many bytes that character occupies, so that a program can step through a multibyte string.

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