250+ TOP MCQs on General Utilities and Answers

C MCQs 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()
Answer: c
Clarification: 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.

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
Answer: a
Clarification: 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()
Answer: b
Clarification: mbtowc() function is used to convert the multibyte character to wide character.

4. Which function converts the wide-character string to a multibyte string?
a) wcstombs()
b) mbstowcs()
c) mbtowc()
d) mblen()
Answer: a
Clarification: 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()
Answer: d
Clarification: 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.

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
Answer: a
Clarification: 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?

#include  
_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
Answer: a
Clarification: 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.

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

#include  
_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
Answer: b
Clarification: 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
Answer: a
Clarification: 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
Answer: a
Clarification: 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.

Leave a Reply

Your email address will not be published. Required fields are marked *