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

Library Functions Questions and Answers

61.

What does the strcmp() function return when the two strings compared are identical ?

Answer: B

Correct answer: 0

strcmp() returns zero for identical strings, a negative value when the first sorts before the second and a positive value otherwise. The common mistake is to treat a zero return as false and so invert the test.

Please log in or register to report this question.

62.

Input/output function prototypes and macros are defined in which header file?

Answer: C

Correct answer: stdio.h

<stdio.h> declares the input and output functions - printf, scanf, fopen, fgets - and the macros and types they use, including FILE, EOF, NULL and the SEEK_ constants. conio.h and dos.h are non-standard DOS headers.

Please log in or register to report this question.

63.

Which header file must be included to use the printf() and scanf() functions ?

Answer: C

Correct answer: stdio.h

The standard input and output declarations, including printf and scanf, live in stdio.h. stdlib.h provides memory allocation and conversion routines, string.h the string handling functions and math.h the mathematical ones.

Please log in or register to report this question.

64.

The _______ function sorts an array of objects.

Answer: D

Correct answer: qsort()

qsort() sorts an array in place, given the base address, the number of elements, the size of each, and a comparison function the caller supplies. Passing the comparison as a function pointer is what makes it work on any type at all. The other three names do not exist.

Please log in or register to report this question.

65.

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.

66.

The source filename and line number come from the preprocessor macros________and______

Answer: A

Correct answer: _ _FILE_ _ and _ _LINE_ _

__FILE__ expands to the current source file name as a string and __LINE__ to the current line number. They are what assert uses to report where a failure occurred, and they are indispensable in logging macros.

Please log in or register to report this question.

68.

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

In the program, printf() returns the number of charecters printed on the console

i = printf("How r u\n"); This line prints "How r u" with a new line character and returns the length of string printed then assign it to variable i.
So i = 8 (length of '\n' is 1).

i = printf("%d\n", i); In the previous step the value of i is 8. So it prints "8" with a new line character and returns the length of string printed then assign it to variable i. So i = 2 (length of '\n' is 1).

printf("%d\n", i); In the previous step the value of i is 2. So it prints "2".

Please log in or register to report this question.

69.

Which of the given function differs from the statement'errno is not neccessarily set on conversion error'?

Answer: D

Correct answer: strtod()

strtod is the one that does report the error: on overflow or underflow it sets errno to ERANGE, and it also returns a pointer to the first character it could not convert. atof, atoi and atol simply return 0 on failure, which is indistinguishable from a legitimate 0 - which is why the strto family should be used in real code.

Please log in or register to report this question.

70.

mblen() function returns 0,if a null wide character was recognized. It returns -1 if an invalid multi-byte sequence was encountered.

Answer: A

Correct answer: true

mblen() returns 0 for a null character, -1 for an invalid multibyte sequence, and otherwise the number of bytes the character occupies. The three cases together are what let a program walk a multibyte string safely.

Please log in or register to report this question.

Loading…

Other Subjects

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