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

Library Functions Questions and Answers

1.

Match the List-I with List II and select the correct answer using the codes given below :

List I 'C' FunctionList II Include File
(a) a cos (d)(i) time.h
(b) abs (i)(ii) stdio.h
(c) fprint (f, ..........)(iii) math.h
(d) time (p)(iv) stdlib.h

Exam Year(s)

MH SET - 2018, SET Exam - 2018,

Answer: B

The correct matching is a-iii, b-iv, c-ii, d-i.

  • acos(d), the inverse cosine, is declared in math.h (iii).
  • abs(i), the integer absolute value, is declared in stdlib.h (iv).
  • fprintf(f, ...), printed as fprint, writes formatted output to a file stream and is in stdio.h (ii).
  • time(p) is declared in time.h (i).

A common slip is to look for abs in math.h, which holds fabs for floating-point values; the integer abs lives in stdlib.h, which rules out the codes giving it math.h.

Please log in or register to report this question.

2.

A Program contains the following declarations and initial assignments
int i = 8, j = 5;
double x = 0.005, y = -0.01;
char c='c', d='d';
Determine the value of the following expressions which involve the use of library functions:
abs(i-2*j) ; log(exp(x)) ; toupper(d)

Exam Year(s)

UGC NET - 2013,

Answer: A

The values are 2, 0.005 and D. With i = 8 and j = 5, abs(i - 2*j) = abs(8 - 10) = 2. The function log(exp(x)) returns x, so it is 0.005. The function toupper('d') returns the capital letter D.

\[ \text{abs}(8 - 10) = 2 \]

\[ \log(e^{0.005}) = 0.005 \]

\[ \text{toupper}(d) = \text{D} \]

The options giving 1 for the first value are wrong, because the difference is -2 and its absolute value is 2. The options with E or lower case e are wrong because toupper of d is D.

Please log in or register to report this question.

Answer: B

The header stdio.h contains the prototypes of the standard input and standard output functions, such as printf, scanf, getchar and putchar, together with related definitions. That is why a program that reads from the keyboard or writes to the screen includes it.


Options (C) and (D) name only a subset: functions that read from files, and functions that work with strings held in memory. Option (A) says nothing more than the header's own name, "standard input/output library", without naming the standard input and standard output functions that give the header its purpose, so the keyed option (B) is the one that states what the header covers.

Please log in or register to report this question.

4.

The function "isalnum( )" returns a non-zero value if the character is alphanumeric and zero otherwise. What is header file to be used in the main program ?

Exam Year(s)

UGC NET - 2014,

Answer: C

The header file is ctype.h. The function isalnum() is declared in ctype.h along with the other character-class functions such as isalpha(), isdigit() and toupper().

stdio.h holds input and output functions such as printf and scanf, string.h holds string functions such as strlen and strcpy, and io.h is a system-specific header for low-level file operations, not for character tests.

Please log in or register to report this question.

5.

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.

6.

What will be the output of the following C code?

int main () 
{ 
   printf("starting of program\n"); 
   printf("program exits\n"); 
   exit(0);  
   printf("program ends\n");  
   return(0); 
}

 

Answer: B

Correct answer: starting of program program exits

exit(0) terminates the program immediately, so the third printf and the return are never reached. Only the first two lines appear. Unlike return from main, exit can be called from anywhere and ends the whole program.

Please log in or register to report this question.

Answer: B

int system(const char *command) function is used to pass the command name or the program name specified by command to the host environment to be executed by the command processor and returns after the command has been completed.

Please log in or register to report this question.

8.

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.

9.

Initial seed is ________ for the function srand(unsigned int seed).

Answer: A

Correct answer: 1

If srand is never called, rand behaves as though srand(1) had been - the initial seed is 1. That is why an unseeded program produces the same sequence every time it runs.

Please log in or register to report this question.

Answer: C

Correct answer: specifies maximum value returned by rand()

RAND_MAX is the largest value rand() can return, guaranteed to be at least 32767. It is needed to scale the result - rand() / (RAND_MAX + 1.0) gives a fraction between 0 and 1. srand returns nothing at all.

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