C Questions and Answers – Character Handling – 2

«
»

This set of C Multiple Choice Questions & Answers focuses on “Character Handling – 2”.

1. The________function converts an uppercase letter to the corresponding lowercase letter.
a) islower()
b) isupper()
c) toupper()
d) tolower()
View Answer

Answer: d
Explanation: If the argument is a character for which isupper() is true and islower() is true for another set of character, the tolower() function returns the corresponding character;otherwise, the argument is returned unchanged.
advertisement

2. The toupper() function converts a ______ to the corresponding ______
a) uppercase, lowercase
b) lowercase, uppercase
c) binary, decimal
d) decimal, binary
View Answer

Answer: b
Explanation: The toupper() function is used to convert a lowercase letter to the corresponding uppercase letter.
If the value is a character for which islower() is true and isupper () is true for another set of characters, the toupper() function returns the corresponding character, otherwise, the value is returned unchanged.

3. fgetc, getc, getchar are all declared in ________
a) stdio. h
b) ctype. h
c) assert. h
d) stdarg. h
View Answer

Answer: a
Explanation: The functions getc, fgetc, getchar are all declared in stdio.h header file.
advertisement
advertisement

4. isalpha() function is used to detect characters both in uppercase and lowercase.
a) true
b) false
View Answer

Answer: a
Explanation: isalpha() function is used to test for letters in the local alphabet. For the locale, the local alphabet consists of 26 English letters, in each of two cases.

5. What will be the output of the following C code?

advertisement
int ch= ' ';
if(isgraph(ch))
printf("ch = %c can be printed \n",ch);
else
printf("ch=%c cannot be printed \n",ch);

a) ch = ‘ ‘ can be printed
b) ch = ‘ ‘ cannot be printed
c) compile error
d) run-time error
View Answer

Answer: b
Explanation: void isgraph() function is used to check if the character has graphical representation. Graphical representations character are all those characters that can be printed except for whitespace characters, which is not considered as isgraph characters.
advertisement

6. The C library function checks whether the passed character is printable.
a) isgraph()
b) isalpha()
c) isprint()
d) ispunct()
View Answer

Answer: c
Explanation: int isprint(int c) function is used to check whether the passed character can be printed.A control character is not a printable character.

7. What will be the output of the following C code?

advertisement
char ch[ ] = "0xC";
if(isxdigit(ch[ ]))
printf("ch = %s is hexadecimal character \n",ch);
else
printf("ch = %s is not hexadecimal character \n",ch);

a) ch = 0xC is hexadecimal character
b) ch = 0xC is not hexadecimal character
c) compile error
d) run-time error
View Answer

Answer: a
Explanation: The C library function isxdigit checks whether the passed character is a hexadecimal digit.

8. Which among the following option is the full set of character class Hexadecimal digits?
a) { 0 1 2 3 4 5 6 7 8 9 A B C D E F }
b) { 0 1 2 3 4 5 6 7 8 9 a b c d e f }
c) { 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f }
d) { 0 1 2 3 4 5 6 7 8 9}
View Answer

Answer: c
Explanation: digit or one of the first letters of the alphabet in either case, ‘a’ through ‘f’ and ‘A’ through ‘F’ is contained in the character class Hexadecimal digits.

9. What will be the output of the following C code?

int i = 0;
char c;
char str[ ] = "Little Star";
while(str[i])
{
putchar (toupper(str[i]));
i++;
}

a) little star
b) lITTLE sTAR
c) LITTLE STAR
d) Little Star
View Answer

Answer: c
Explanation: The C library function toupper converts the lowercase letter to uppercase.

10. What will be the output of the following C code?

int ch = '\t';
if(isprint(ch))
printf("ch = |%c| printable  \n", ch);
else
printf("ch= |%c| not printable \n",ch);

a) ch = |\t| printable
b) ch = |\t| not printable
c) ch = | | printable
d) ch = | | not printable
View Answer

Answer: d
Explanation: isprint() function is used to check whether the passed character is printable. A control character is not a printable 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