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

Library Functions Questions and Answers

51.

What error occurs if an input argument is outside the domain over which the mathematical function is defined?

Answer: A

Correct answer: domain error

A domain error occurs when an argument lies outside the set of values for which the function is defined - sqrt(-1) or asin(2). The function returns an implementation-defined value and sets errno to EDOM. A range error is the other case: the argument is fine but the result cannot be represented.

Please log in or register to report this question.

52.

_______variable type defined in the header stdlib.h is an integer type of the size of a wide character constant.

Answer: B

Correct answer: wchar_t

wchar_t is the integer type large enough to hold any character of the extended character set - the type of a wide character constant such as L'x'. size_t is for sizes, and div_t and ldiv_t are the structures returned by div and ldiv.

Please log in or register to report this question.

53.

Point out the error in the following program.

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

int main()
{
    char str1[] = "Learn through IndiaBIX\0.com",  str2[120];
    char *p;
    p = (char*) memccpy(str2, str1, 'i', strlen(str1));
    *p = '\0';
    printf("%s", str2);
    return 0;
}

 

Answer: D

Correct answer: No error and prints "Learn through Indi"

memccpy copies bytes until the given character has been copied, and returns a pointer to the byte after it - or NULL if the character never appeared. The first lower-case 'i' in the string is the one in Indi, so the copy stops there, the returned pointer is used to write the terminating null, and the result is Learn through Indi.

Please log in or register to report this question.

54.

sqrt(x) function is not faster than the apparent equivalent pow(x,0.5).

Answer: B

Correct answer: false

sqrt(x) is faster - often much faster - than pow(x, 0.5). Square root is a single hardware instruction on most processors, whereas pow is a general routine computing an exponential and a logarithm. It is also more accurate, so sqrt should always be preferred.

Please log in or register to report this question.

55.

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.

56.

What will be the output of the program?

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

int main()
{
    char dest[] = {97, 97, 0};
    char src[] = "aaa";
    int i;
    if((i = memcmp(dest, src, 2))==0)
        printf("Got it");
    else
        printf("Missed");
    return 0;
}

 

Answer: B

memcmp compares the first 2 bytes of the blocks dest and src as unsigned chars. So, the ASCII value of 97 is 'a'.

if((i = memcmp(dest, src, 2))==0) When comparing the array dest and src as unsigned chars, the first 2 bytes are same in both variables.so memcmp returns '0'.
Then, the if(0=0) condition is satisfied. Hence the output is "Got it".

Please log in or register to report this question.

57.

Point out the error in the following program.

#include <stdio.h>

int main()
{
    fprintf("IndiaBIX");
    printf("%.ef", 2.0);
    return 0;
}

 

Answer: B

Correct answer: Error: in fprintf() statement

fprintf requires a stream as its first argument - fprintf(stdout, "..."). Called with only a string it is missing that argument, and the string is taken as the stream, which is a type error. Plain printf is the version that writes to stdout without being told.

Please log in or register to report this question.

Answer: C

Correct answer: standard error streams

stderr is one of the three standard streams opened automatically, alongside stdin and stdout. Error messages go to it rather than to stdout so that they still appear when the program’s output is redirected to a file - and because it is unbuffered, they appear at once.

Please log in or register to report this question.

59.

MB_CUR_MAX is not defined in stdlib.h.

Answer: B

Correct answer: false

MB_CUR_MAX is defined in <stdlib.h>. It gives the maximum number of bytes in a multibyte character for the current locale, and it is needed by the conversion functions such as mbtowc.

Please log in or register to report this question.

60.

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