250+ TOP MCQs on Character Classification and Answers

C++ Programming Multiple Choice Questions & Answers (MCQs) on “Character Classification”.

1. Which function is used to check whether a character is an alphabet?
a) isalpha()
b) isalnum()
c) isdigit()
d) isblank()
Answer: a
Clarification: Character classification provides isalpha() function to check whether a character in C++ is an alphabet or not.

2. Which function is used to check whether a character is an alphabet or number?
a) isalpha()
b) isalnum()
c) isdigit()
d) isblank()
Answer: b
Clarification: Character classification provides isalnum() function to check whether a character in C++ is alphabet or number.

3. Which function is used to check whether a character is a number?
a) isalpha()
b) isalnum()
c) isdigit()
d) isblank()
Answer: c
Clarification: Character classification provides isdigit() function to check whether a character in C++ is number or not.

4. Which function is used to check whether a character is a tab or space?
a) isalpha()
b) isalnum()
c) isdigit()
d) isblank()
Answer: d
Clarification: Character classification provides isblank() function to check whether a character in C++ is space or tab.

5. Which function is used to check whether a character is tab or space or whitespace control code(n,r,etc.)?
a) isspace()
b) isalnum()
c) iscntrl()
d) isblank()
Answer: a
Clarification: Character classification provides isspace() function to check whether a character in C++ is tab or space or whitespace control code(n, r, etc.).

6. Which function is used to check whether a character is tab or a control code?
a) isspace()
b) isalnum()
c) iscntrl()
d) isblank()

Answer: c
Clarification: Character classification provides iscntrl() function to check whether a character in C++ is tab or a control code.

7. Which function is used to check whether a character is printable on console?
a) isxdigit()
b) isprint()
c) iscntrl()
d) ispunct()
Answer: b
Clarification: Character classification provides isprint() function to check whether a character in C++ is printable on console.

8. Which function is used to check whether a character is hexadecimal?
a) isxdigit()
b) isprint()
c) iscntrl()
d) ispunct()
Answer: a
Clarification: Character classification provides isxdigit() function to check whether a character in C++ is hexadecimal.

9. Which function is used to check whether a character is punctuation mark?
a) isxdigit()
b) isprint()
c) iscntrl()
d) ispunct()
Answer: d
Clarification: Character classification provides ispunct() function to check whether a character in C++ is punctuation mark.

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

#include 
#include 
using namespace std;
int main(int argc, char const *argv[])
{
	char arr[12] = "Hello World";
	for(int i=0;i<12;i++)
        {
		cout<<(bool)isalpha(arr[i]);
	}
}

a) 111110111110
b) 111111111110
c) 111000111110
d) 111110000000
Answer: a
Clarification: In this program we are checking whether a character is an alphabet or not so in “Hello World” except space everything is alphabet, therefore, we have 11111011111 but it is followed by a 0 because every string is followed by a null character which is not alphabet, therefore, we have 0 at the of the binary string.

11. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main(int argc, char const *argv[])
{
	char arr[12] = "H3ll0 W0r1d";
	for(int i=0;i<12;i++)
        {
		cout<<(bool)isalpha(arr[i]);
	}
	cout<<endl;
	for(int i=0;i<12;i++)
        {
		cout<<(bool)isdigit(arr[i]);
	}
}

a)

000000000000
010010010100

b)

101100100010
010010010111

c)

111111101010
010010000000

d)

101100101010
010010010100

View Answer

Answer: d
Clarification: In this program, we are first checking the alphabets in the string then digits in the string so accordingly one can find the answer.

 
 

12. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main(int argc, char const *argv[])
{
	char arr[12] = "H3ll0tW0r1d";
	for(int i=0;i<12;i++)
        {
		cout<<(bool)isprint(arr[i]);
	}
}

a) 111000111110
b) 111111111110
c) 111110111110
d) 111110000000
Answer: c
Clarification: In this program we are checking the presence of alphabets and digits in the string so accordingly one can find the answer.

13. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main(int argc, char const *argv[])
{
	char arr[12] = "H3ll0tW0r1d";
	for(int i=0;i<12;i++)
        {
		cout<<(bool)iscntrl(arr[i]);
	}
}

a) 111111111110
b) 000001000001
c) 111000111110
d) 111110000000
Answer: b
Clarification: In this program we are checking the presence of control codes i.e. n, r, rn, t, etc. in the string so accordingly one can find the answer.

14. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main(int argc, char const *argv[])
{
	char arr[20] = "'H3ll0'";
	for(int i=0;i<8;i++)
        {
		cout<<(bool)ispunct(arr[i]);
	}
}

a) 10000010
b) 111111111110
c) 111000111110
d) 111110000000
Answer: a
Clarification: In this program we are checking the presence of punctuation characters like quotes(‘, “, etc.) in the string, so ispunct() returns 1 for single quote positions and returns 0 otherwise.

15. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main(int argc, char const *argv[])
{
	char arr[27] = "abcdefghijklmnopqrstuvwxyz";
	for(int i=0;i<27;i++)
        {
		cout<<(bool)isxdigit(arr[i]);
	}
}

a) 111001100011110000000111100
b) 101010101010101001010101010
c) 111111000000000000000000000
d) 111111111000001111011110111
Answer: c
Clarification: In this program, we are checking the presence of hexadecimal characters in the string and as only a, b, c, d, e and f are used as hexadecimal characters therefore only first bits are 1 and others are 0.

Leave a Comment

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

Scroll to Top