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

Library Functions Questions and Answers

41.

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.

42.

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.

43.

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.

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.

45.

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.

46.

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.

47.

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.

48.

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.

49.

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.

50.

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.

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