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

Library Functions Questions and Answers

Answer: C

Correct answer: unsigned integer

size_t is the unsigned integer type returned by sizeof - it must be able to hold the size of the largest object, and a size is never negative. That it is unsigned is a common source of bugs: a loop written for (size_t i = n-1; i >= 0; i--) never ends.

Please log in or register to report this question.

Answer: D

Correct answer: Reposition the file pointer to the beginning of the file

rewind(fp) moves the file position indicator back to the beginning of the file and clears the error and end-of-file flags. It is equivalent to fseek(fp, 0L, SEEK_SET), except that it returns nothing and resets the flags.

Please log in or register to report this question.

93.

What will be the output of the program?

#include <stdio.h>
#include<math.h>

int main()
{
    float i = 2.5;
    printf("%f, %d", floor(i), ceil(i));
    return 0;
}

 

Answer: C

Both ceil() and floor() return the integer found as a double.

floor(2.5) returns the largest integral value(round down) that is not greater than 2.5. So output is 2.000000.

ceil(2.5) returns 3, while converting the double to int it returns '0'.
So, the output is '2.000000, 0'.

Please log in or register to report this question.

94.

How many macros are defined in the header file stdarg.h?

Answer: C

Correct answer: three

Classic <stdarg.h> defines three macros - va_start, va_arg and va_end - together with the type va_list. (C99 added a fourth, va_copy.) They are what let a function such as printf reach arguments the compiler cannot type-check.

Please log in or register to report this question.

95.

What will be the output of the following C code?

void main() 
{ 
   div_t  res;  
   res = div(34, 4); 
   printf("quotient part = %d\n", res.quot); 
   printf("remainder part = %d\n", res.rem); 
}

 

Answer: B

Correct answer: quotient part=8 remainder part=2

div(34, 4) returns a div_t structure holding both results at once: quotient 8 and remainder 2, since \(34 = 8 \times 4 + 2\). Computing both together is cheaper than a separate / and %, and the sign behaviour is guaranteed to truncate toward zero.

Please log in or register to report this question.

96.

The macro which is used to find the maximum value of an unsigned integer is _________

Answer: C

Correct answer: UINT_MAX

UINT_MAX, in <limits.h>, is the largest value an unsigned int can hold - at least 65535, and 4294967295 where the type is 32 bits. There is no corresponding minimum, since it is always 0.

Please log in or register to report this question.

97.

Which of the following library functions returns the time in UTC (Greenwich mean time) format?

Answer: C

Correct answer: gmtime()

gmtime() converts a time_t to a struct tm expressed in UTC, while localtime() does the same in local time, applying the time zone and any daylight saving. Using UTC avoids every ambiguity of zones and clock changes, which is why logs and timestamps are usually kept in it.

Please log in or register to report this question.

98.

Select the function that reads or sets location dependent information.

Answer: B

Correct answer: setlocale()

setlocale() reads or sets the program’s locale - the conventions for decimal points, currency, dates, character classification and collating order. Until it is called with something other than "C", a program uses the minimal default locale whatever the system is set to.

Please log in or register to report this question.

Answer: C

Correct answer: has # as the first character

A directive is recognised by the #, which must be the first non-blank character on its own line. It may be indented, but nothing else may precede it on that line, and it must not be placed after other code. Nor need it come before the first executable statement - directives may appear anywhere in the file.

Please log in or register to report this question.

Answer: D

Correct answer: All of the above

The preprocessor does all three: file inclusion through #include, macro expansion through #define, and conditional compilation through #if and its relatives. All of it happens on the text before the compiler proper sees anything.

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