250+ TOP MCQs on General Utilities and Answers

C Multiple Choice Questions & Answers on “General Utilities – 6”.

1. What will the code display on compiling?

void funccall() 
{ 
   printf("this is funccalln"); 
}  
void main () 
{   
    atexit(funccall); 
    printf("program startsn");  
    printf("program endsn");  
}

a)

   program starts
   this is funccall
   program ends

b)

   this is funccall
   program starts
   program ends

c)

   program starts
   program ends
   this is funccall

d) error
Answer: c
Clarification: 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.

2. What will be the output of the following C code?

int main () 
{ 
   printf("starting of programn"); 
   printf("program exitsn"); 
   exit(0);  
   printf("program endsn");  
   return(0); 
}

a)

   starting of program
   program exits
   program ends

b)

   starting of program
   program exits

c)

   starting of program
   program ends

d) error
Answer: b
Clarification: void exit(int status) function is used to terminate the calling process immediately.

3. What will the following C code do on compilation?

void main () 
{
   char com[50];  
   strcpy( com, "dir" ); 
   system(com); 
}

a) error
b) lists down all the files and directories in the current directory under windows machine
c) terminates the calling process immediately
d) calls specified function and terminates it at the end of the program
Answer: b
Clarification: 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.

4. What will be the output of the following C code?

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

a)

    quotient part=0
    remainder part=4

b)

    quotient part=8
    remainder part=2

c)

    quotient part=4
    remainder part=0

d)

    quotient part=2
    remainder part=8

View Answer

Answer: b
Clarification: div_t div(int n, int d) used to divide n (numerator) by d (denominator). div_t is a structure defined in ,which has two members
int quot;
in rem;

 
 

5. Initial seed is ________ for the function srand(unsigned int seed).
a) 0
b) 1
c) 00
d) 01
Answer: b
Clarification: void srand(unsigned int seed);
This function returns a new sequence of pseudo-random numbers using the specified seed.Initial seed is 1.

6. Which statement is true with respect to RAND_MAX?
a) specifies value for status argument to exit indicating failure
b) specifies value for status argument to exit indicating success
c) specifies maximum value returned by rand()
d) specifies maximum value returned by srand()
Answer: c
Clarification: RAND_MAX specifies maximum value that has to returned by the function rand().
rand() function returns a pseudo-random number in the range 0 to RAND_MAX.

7. Which of the given function differs from the statement’errno is not neccessarily set on conversion error’?
a) atof()
b) atoi()
c) atol()
d) strtod()
Answer: d
Clarification: The function atoi() and atol() are similar to strtol(), atof() is similar to strtod() except that errono is not necessarily set on conversion error.

8. void free(void *p) performs which of the following functions?
a) returns pointer to allocated space for existing contents of p
b) de-allocates space to which p points
c) to abnormally terminate the program
d) no such function defined in stdlib.h
Answer: b
Clarification: void free(void *p);
This function de-allocates space to which p points(if p is not NULL).

9. Which of the given option is declared under the header file stdlib.h?
a) SEEK_CUR
b) SEEK_END
c) CLOCKS_PER_SEC
d) EXIT_SUCCESS
Answer: d
Clarification: SEEK_CUR and SEEK_END is defined under stdio.h, CLOCKS_PER_SEC is defined under time.h, EXIT_SUCCESS is defined under stdlib.h.
EXIT_SUCCESS specifies value for status argument to exit indicating success.

10. MB_CUR_MAX is not defined in stdlib.h.
a) true
b) false
Answer: b
Clarification: MB_CUR_MAX is defined under header file stdlib.h .
MB_CUR_MAX expands into a positive integer expression.It is the maximum number of bytes in a multibyte character present in the current locale.

Leave a Reply

Your email address will not be published. Required fields are marked *