C Questions and Answers – General Utilities – 5

«
»

This set of C MCQs focuses on “General Utilities – 5”.

1. The number of bytes contained in the multibyte character pointed to by a character is ___________
a) getenv()
b) bsearch()
c) mblen()
d) qsort()
View Answer

Answer: c
Explanation: int mblen(const char *s, size-t n);
If s is not a null pointer, the mblen() function is used to determine the number of bytes contained in the multibyte character pointed to by s.

advertisement

2. The pointer used in the mblen() function points to the _________
a) first byte of multibyte character
b) last byte of multibyte character
c) middle byte of multibyte character
d) no pointer is used in mblen function
View Answer

Answer: a
Explanation: The prototype of the functon mblen() is int mblen(const char *s,size_t n); The pointer ‘s’ points to the first byte of the multibyte character.

3. What is the name of the function that is used to convert multibyte character to wide character?
a) mblen()
b) mbtowc()
c) mbstowcs()
d) wcstombs()
View Answer

Answer: b
Explanation: mbtowc() function is used to convert the multibyte character to wide character.
advertisement
advertisement

4. Which function converts the wide-character string to a multibyte string?
a) wcstombs()
b) mbstowcs()
c) mbtowc()
d) mblen()
View Answer

Answer: a
Explanation: The C library function size_t wcstombs(char *ptr, const wchar_t *ws, size_t n) is used to convert the wide-character string was to a multibyte string starting at ptr. At most n bytes are written to ptr.

5. The C library function _____________function converts the wide character to its multibyte representation.
a) mblen()
b) mbtowc()
c) wcstombs()
d) wctomb()
View Answer

Answer: d
Explanation: wctomb() is a C Library function which converts the wide character into its multibyte representation. It is stored at the beginning of the character array pointed to by the respective pointer.
advertisement

6. The mbstowcs() function is used to return the number of array elements modified, not including a terminating zero code, if any.
a) true
b) false
View Answer

Answer: a
Explanation: mbstowcs() function returns the number of array elements that are modified. It does not return a terminating zero code if any. The mbstowcs() function is used to convert a sequence of multibyte characters that begins in the initial shift state from the array pointed to by, into a sequence of corresponding codes.

7. What will the given C code do?

advertisement
#include <stdlib.h> 
_Mbsave_Mbxlen={0};
int (mblen)(const char *s ,size_t n)
{
return(_Mbtowc(NULL s,n,&_Mbxlen));
}

a) determine length of next multibyte code
b) determine next multibyte code
c) translate multibyte string to wide char string
d) translate wide character to multibyte string
View Answer

Answer: a
Explanation: mblen() function is used to return the length of a multi-byte character pointed to, by the argument s. The data objects _Mbxlen and _Mbxtowc both have names with external linkage.
advertisement

8. What is the purpose of the given C code?

#include <stdlib.h> 
_Mbsave _Mbxtowc = {0};  
int (mbtowc) (wchar_t *pwc, const char *a, size_t n) 
{
return (-Mbtowc (pwc, s, n, &-Mbxtowc) ) ;
}

a) determine length of next multibyte code
b) translates multibyte character to wide character
c) translate multibyte string to wide char string
d) translate wide character to multibyte string
View Answer

Answer: b
Explanation: int mbtowc(whcar_t *pwc, const char *a, size_t n)
The given function is used to convert a multibyte sequence to a wide character.

9. What is “a” in the given C code?

size_t wcstombs(char *s, const wchar_t *a, size_t n)

a) “a” is wide character string to be converted
b) “a” is pointer to an array of char elements
c) “a” is pointer to the first byte of a multi-byte character
d) “a” C multibyte character string to be interpreted
View Answer

Answer: a
Explanation: The wcstombs() function is used to convert a sequence of codes that correspond to multibyte characters from the array pointed to by ‘a’ into a sequence of multibyte characters beginning in the initial shift state and stores these multibyte characters into the array pointed to by s.
size_t wcstombs(char *s, const wchar_t *a, size_t n)

10. mblen() function returns 0,if a null wide character was recognized. It returns -1 if an invalid multi-byte sequence was encountered.
a) true
b) false
View Answer

Answer: a
Explanation: int mblen(const char *a, size-t n);
If in the given code “a” points to a NULL character then the function returns 0 or -1 is returned if they do not form a valid multibyte character.

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