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

Library Functions Questions and Answers

11.

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

The ungetc() function pushes the character c back onto the named input stream, which must be open for reading.

This character will be returned on the next call to getc or fread for that stream.

One character can be pushed back in all situations.

A second call to ungetc without a call to getc will force the previous character to be forgotten.

Please log in or register to report this question.

Answer: A

Correct answer: The abs() function is similar to the labs() function, except that the argument and the returned value each of them have type long int

The two do the same thing for different types: abs takes and returns an int, and labs takes and returns a long int. (llabs was added for long long, and fabs handles floating point.)

Please log in or register to report this question.

13.

FILE is a structure suitably typedef'd in "stdio.h".

Answer: A

Correct answer: True

FILE is a structure type defined in <stdio.h>, holding the buffer, the position indicator and the state flags for a stream. Programs use it only through a FILE * and never look inside - its contents are the implementation’s business.

Please log in or register to report this question.

14.

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

Answer: D

Correct answer: strtod()

strtod is the one that does report errors: on overflow or underflow it sets errno to ERANGE, and it also returns a pointer to the first unconverted character. The ato family - atoi, atof, atol - simply return 0 on failure and set nothing, which is why the strto functions should be preferred.

Please log in or register to report this question.

15.

Point out the error in the following program.

#include <stdio.h>

int main()
{
    fprintf("Compscibits");
    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.

16.

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 'a' */
        printf("%c", c);
        ungetc(c, stdin);
    }
    return 0;
}

 

Answer: B

Correct answer: aaaaa

ungetc pushes the character back onto the input stream, so the next scanf reads the same character again. The loop therefore reads and prints the same a on all five passes, giving aaaaa. Only one character of pushback is guaranteed, which is all this needs.

Please log in or register to report this question.

17.

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 'a' */
        printf("%c", c);
        ungetc(c, stdin);
    }
    return 0;
}

 

Answer: B

Correct answer: aaaaa

ungetc pushes the character back onto the input stream, so the next scanf reads the same character again. The loop therefore reads and prints the same a on all five passes, giving aaaaa. Only one character of pushback is guaranteed, which is all this needs.

Please log in or register to report this question.

18.

In the c library function void (*signal(int sig, void (*func)(int)))(int), which statement is true with respect to func?

Answer: A

Correct answer: func is a pointer to the function

Read the declaration outwards: void (*func)(int) makes func a pointer to a function taking an int and returning nothing - the handler to be installed. signal itself returns a pointer of the same kind, namely the previous handler, which is what makes the declaration so hard to read.

Please log in or register to report this question.

19.

If the result underflows, the function returns zero.

Answer: A

Correct answer: true

On underflow - a result too small in magnitude to be represented - a maths function returns zero, and may set errno to ERANGE. That contrasts with overflow, where it returns HUGE_VAL.

Please log in or register to report this question.

Answer: D

Correct answer: pointer to the current location

localeconv() returns a pointer to a struct lconv describing the conventions of the locale currently in force - decimal point, thousands separator, currency symbol and its placement. The structure is static, so its contents change when the locale is changed.

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