This set of C Multiple Choice Questions & Answers (MCQs) focuses on “General Utilities – 6”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. 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"); }
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
View Answer
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?
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
b)
starting of program program exits
c)
starting of program program ends
d) error
View Answer
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
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=8View Answer
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
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
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
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
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
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
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.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Buy C Books
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Practice BCA MCQs
- Watch Advanced C Programming Videos