C Questions and Answers – General Utilities – 4

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “General Utilities – 4”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. Which of the given function is used for searching?
a) lsearch()
b) bsearch()
c) csearch()
d) qsearch()
View Answer

Answer: b
Explanation: bsearch() function is used to search an array of objects, the initial element is pointed by base, for an element that matches the object is pointed by key. The size of each element of the array is specified by size.

2. Which function is called repeatedly by bsearch() to compare search elements against the elements in the array?
a) mblem()
b) wctomb()
c) compar()
d) labs()
View Answer

Answer: c
Explanation: void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *))
The comparison function pointed to by compar() is called with two arguments that point to the key object to be searched and to an array element, in that order. The function shall return a < 0, = 0, or > 0 if the key object is considered, respectively, to be less than, to match, or to be greater than the array element.
advertisement
advertisement

3. The _______ function sorts an array of objects.
a) bsort()
b) hsort()
c) ssort()
d) qsort()
View Answer

Answer: d
Explanation: void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void*))
The qsort() function is used to sort an array of nmemb objects, the initial element of array is pointed to by base. The size of each object in array is specified by size. The contents of the array are sorted into ascending order according to a comparison function pointed to by compar.

4. Choose the correct statement.
a) bsearch() returns no value to the function
b) getenv() returns no value to the function
c) qsort() returns no value to the function
d) realloc() returns no value to the function
View Answer

Answer: c
Explanation: The qsort() function does not return any value.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

5. Which statement is true regarding abs() and labs()?
a) The abs() function is similar to the labs() function, except that the argument and the returned value each of them have type long int
b) The abs() function is not similar to the labs() function, except that the argument and the returned value in both functions have type long int
c) The abs() function is similar to the labs() function, except that the argument and the returned value each have type short int
d) The abs() function is not similar to the labs() function, except that the argument and the returned value in both function have type short int
View Answer

Answer: a
Explanation: long int labs(long int i);
The abs() function is similar to the labs() function, except that the returned value and argument each are of type long int.

6. The abs() function computes the absolute value __________
a) a floating number
b) an integer number
c) a double number
d) all of the mentioned
View Answer

Answer: b
Explanation: int abs (int i);
The abs() function is used to compute the absolute value of an integer i. If the result cannot be represented, the behavior is undefined.
advertisement

7. Which function will return the quotient and remainder on division of numerator with denominator?
a) div()
b) div_t()
c) ldiv_t()
d) labs()
View Answer

Answer: a
Explanation: div_t div(int num, int den);
The div () function is used to compute the quotient and remainder of the division of the numerator num by the denominator den.div_t is the structure which contains a quotient member and a remainder member.

8. What members do the structure returned by function div() contains?
a) int quot and int rem
b) float quot and float rem
c) double quot and double rem
d) no members are returned by div()
View Answer

Answer: a
Explanation: A structure of type div_t is returned by the function div(), contains both the quotient and the remainder. The structure contains two members,
int quot; /* quotient */
int rem; /* remainder */
advertisement

9. Which of the given structure is returned by the function ldiv()?
a) div_t
b) ldiv_t
c) div_i
d) ldiv_i
View Answer

Answer: b
Explanation: ldiv_t is the structure returned by the function div(). ldiv() function is similar to the function div() except that the argument and the returned value is of type long int.

10. Select the multibyte character function defined under the header file stdlib.h.
a) wctomb()
b) mblen()
c) mbtowc()
d) all of the mentioned
View Answer

Answer: d
Explanation: wctomb(), mblen() and mbtowc() are multibyte character function defined under the header file stdlib.h. The LC_CTYPE category of the current locale affects the behaviour of these function.

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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). 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!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.