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

Library Functions Questions and Answers

Answer: B

Correct answer: de-allocates space to which p points

free(p) returns to the heap the block that p points to, obtained earlier from malloc, calloc or realloc. It does not change p itself, which is why the pointer should be set to NULL afterwards - using it again, or freeing it twice, is undefined behaviour.

Please log in or register to report this question.

42.

What will the code display on compiling?

void funccall() 
{ 
   printf("this is funccall\n"); 
}  
void main () 
{   
    atexit(funccall); 
    printf("program starts\n");  
    printf("program ends\n");  
}

 

Answer: C

int atexit(void (*func)(void)) calls the specified function func when the program terminates. we can register termination function anywhere in the program, but it will be called at the time of the program termination.

Please log in or register to report this question.

43.

Which of the following functions returns a pointer to a string representing the date and time stored in a structure?

Answer: C

Correct answer: asctime()

asctime() takes a pointer to a struct tm - a broken-down time - and returns a printable string. ctime() does the same starting from a time_t, and localtime() is what produces the struct tm in between.

Please log in or register to report this question.

44.

It is necessary that for the string functions to work safely the strings must be terminated with '\0'.

Answer: A

C string is a character sequence stored as a one-dimensional character array and terminated with a null character('\0', called NULL in ASCII).
The length of a C string is found by searching for the (first) NULL byte.

Please log in or register to report this question.

45.

The macro definition of INT_MIN is ____________

Answer: A

Correct answer: -INT_MAX – 1

On a two’s-complement machine the negative range is one larger than the positive, so INT_MIN = -INT_MAX - 1 - for 32-bit ints, -2147483648 against 2147483647. A consequence worth knowing: -INT_MIN overflows and cannot be represented.

Please log in or register to report this question.

46.

Point out the error in the following program.

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

int main()
{
    char str1[] = "Learn through Compscibits\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 Compsci"

memccpy copies until the given character has been copied and returns a pointer just past it. The first 'i' in Learn through Compscibits is the one in sci, so the copy stops there and the null written through the returned pointer leaves Learn through Compsci.

Please log in or register to report this question.

47.

What will be the output of the program?

#include <stdio.h>

int main()
{
    int i;
    char c;
    for(i=1; i<=5; i++)
    {
        scanf("%c", &c); /* given input is 'b' */
        ungetc(c, stdout);
        printf("%c", c);
        ungetc(c, stdin);
    }
    return 0;
}

 

Answer: C

Correct answer: b

The first ungetc pushes the character back onto stdout, which is an output stream - the call fails and does nothing. The second pushes it back onto stdin, but only one character of pushback is guaranteed, and the behaviour of this loop is not reliable. On the usual implementations only a single b is printed.

Please log in or register to report this question.

48.

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.

49.

_______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.

50.

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.

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