This set of C++ Programming Multiple Choice Questions & Answers (MCQs) focuses on “Character Classification”.
1. Which function is used to check whether a character is an alphabet?
a) isalpha()
b) isalnum()
c) isdigit()
d) isblank()
View Answer
Explanation: 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()
View Answer
Explanation: 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()
View Answer
Explanation: 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()
View Answer
Explanation: 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()
View Answer
Explanation: 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()
View Answer
Explanation: 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()
View Answer
Explanation: 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()
View Answer
Explanation: 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()
View Answer
Explanation: 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 <iostream> #include <cctype> 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
View Answer
Explanation: 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 <iostream> #include <cctype> 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 010010010100View Answer
Explanation: 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 <iostream> #include <cctype> using namespace std; int main(int argc, char const *argv[]) { char arr[12] = "H3ll0\tW0r1d"; for(int i=0;i<12;i++) { cout<<(bool)isprint(arr[i]); } }
a) 111000111110
b) 111111111110
c) 111110111110
d) 111110000000
View Answer
Explanation: 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 <iostream> #include <cctype> using namespace std; int main(int argc, char const *argv[]) { char arr[12] = "H3ll0\tW0r1d"; for(int i=0;i<12;i++) { cout<<(bool)iscntrl(arr[i]); } }
a) 111111111110
b) 000001000001
c) 111000111110
d) 111110000000
View Answer
Explanation: In this program we are checking the presence of control codes i.e. \n, \r, \r\n, \t, etc. in the string so accordingly one can find the answer.
14. What will be the output of the following C++ code?
#include <iostream> #include <cctype> 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
View Answer
Explanation: 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 <iostream> #include <cctype> 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
View Answer
Explanation: 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.
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.
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Practice Programming MCQs
- Apply for Computer Science Internship
- Buy Computer Science Books
- Buy C++ Books
- Practice Computer Science MCQs