This set of C Multiple Choice Questions & Answers (MCQs) focuses on “General Utilities – 3”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. void free(void *ptr) deallocates the memory previously allocated by a call to _______ ________ or _________
a) malloc,getenv,abort
b) calloc,malloc,exit
c) calloc,malloc,realloc
d) exit,getenv,abort
View Answer
Explanation: The free() function causes the space to be deallocated that are pointed to by ptr, that is, made available for further allocation. No action occurs if ptr is a null pointer. Otherwise, if the argument does not match a pointer earlier returned by the calloc. malloc, or realloc function.
2. The ________ function returns no value.
a) malloc()
b) realloc()
c) free()
d) calloc()
View Answer
Explanation: The calloc() function is used to return either a null pointer or a pointer to the allocated space. The malloc() function is used to return either a null pointer or a pointer to the allocated space. The realloc() function is used to return either a null pointer or a pointer to the possibly moved allocated space. The free() function returns no value.
3. What is returned by the function if the space cannot be allocated by the function malloc(), realloc() and calloc()?
a) value
b) error
c) null pointer
d) no value
View Answer
Explanation: The pointer returned points to the lowest byte address of the allocated space. A null pointer is returned, if the space cannot be allocated.
4. What is the function of the void *realloc(void *str, size-t size);?
a) allocates space for an array of str objects, each of whose size is size
b) allocates space for an object whose size is specified by size and whose value is indeterminate
c) changes the size of the object pointed to by str to the size specified by size
d) causes the space pointed to by str to be deallocated, that is, made available for further allocation
View Answer
Explanation: void *realloc(void *str, size-t size);
The realloc() function is used to change the size of the object which is pointed to by str to the size specified by size.
5. Which among the given function causes abnormal program termination ?
a) exit()
b) abort()
c) atexit()
d) getenv()
View Answer
Explanation: void abort (void);
The abort() function causes abnormal program termination to occur, and comes out directly from that place.
6. Which of the given statement is true with respect to the function atexit()?
a) The atexit() function cannot return to its caller
b) The atexit() function is used to return zero if the registration succeeds, nonzero if it fails
c) The atexit() function returns no value
d) The atexit() function causes abnormal program termination to occur
View Answer
Explanation: The prototype of function is int atexit (void (*func) (void) );
The atexit() function is used to register the function pointed to by func, to be called without arguments at normal program termination.
7. The behavior is undefined if more than one call to the exit function is executed by a program.
a) true
b) false
View Answer
Explanation: The exit() function causes normal program termination to occur. The behavior is undefined if more than one call to the exit function is executed by a program.
8. Which function searches an environmenr list that are provided by the host environment?
a) getenv()
b) system()
c) srand()
d) rand()
View Answer
Explanation: The getenv() searches for the environment string pointed to, by name and returns the associated value to the string.The syntax of function is char *getenv(const char *name).
9. The system() function passes the string pointed to by string to the host environment to be executed by a command processor in an implementation-defined manner.
int system(const char *string);
a) true
b) false
View Answer
Explanation: The system function returns nonzero only if a command processor is available provided if the argument is a null pointer. The system function returns an implementation-defined value, if the argument is not a null pointer.
10. What will be the output of the following C code?
int main(void) { int rc; rc = system("time"); exit(0); }
a) produces error
b) no value is returned
c) returns the time
d) nothing can be said
View Answer
Explanation: The system() function is used to pass the string pointed to by string to the host environment to be executed by a command processor in an implementation-defined manner.
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.
- Practice Computer Science MCQs
- Watch Advanced C Programming Videos
- Apply for C Internship
- Practice BCA MCQs
- Check Computer Science Books