C Questions and Answers – General Utilities – 6

«
»

This set of C Multiple Choice Questions & Answers focuses on “General Utilities – 6”.

1. What will the code display on compiling?

advertisement
void funccall() 
{ 
   printf("this is funccall\n"); 
}  
void main () 
{   
    atexit(funccall); 
    printf("program starts\n");  
    printf("program ends\n");  
}

a)

   program starts
   this is funccall
   program ends
advertisement
advertisement

b)

   this is funccall
   program starts
   program ends

c)

   program starts
   program ends
   this is funccall
advertisement

d) error
View Answer

Answer: c
Explanation: 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?

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

a)

   starting of program
   program exits
   program ends
advertisement

b)

   starting of program
   program exits

c)

   starting of program
   program ends

d) error
View Answer

Answer: b
Explanation: 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
View Answer

Answer: b
Explanation: 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 = %d\n", res.quot); 
   printf("remainder part = %d\n", 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
Explanation: div_t div(int n, int d) used to divide n (numerator) by d (denominator). div_t is a structure defined in <cstdlib>,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
View Answer

Answer: b
Explanation: 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()
View Answer

Answer: c
Explanation: 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()
View Answer

Answer: d
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: b
Explanation: 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.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter