NEW
Font size
WorksheetsQuarter3_Quiz_no.2: C++ Character Data Types
Total questions: 15
Worksheet time: 8mins
A student writes the following code:
char x = 97;
cout << x;
What higher-level reasoning best explains why the output is ‘a’?
Because character variables automatically convert to lowercase letters
Because 97 is directly mapped to ‘a’ in the ASCII table
Because the compiler detects a numeric literal and forces a cast to char
Because numeric values always represent letters in C++
You want to store the symbol ‘&’ using its ASCII value. Which reasoning correctly identifies the value you should assign?
Choose any integer between 0 and 127, because ASCII allows any value
Use the ASCII code that the compiler decides at runtime
Look up the ASCII table and assign the number representing ‘&’
Choose the Unicode value because ASCII is outdated
A student declares:
char c = '\n';
Why will printing this variable not show an actual character?
Because '\n' deletes characters
Because '\n' is an escape sequence that represents an action, not a visible symbol
Because escape sequences are always ignored
Because char cannot hold escape sequences
Consider the line:
char d = '\\';
Why must a double backslash be used?
Because the compiler rejects single character declarations
Because the backslash is reserved for starting escape sequences
Because two backslashes represent a space
Because ASCII requires paired slashes
Which scenario BEST demonstrates implicit type conversion between char and int?
Assigning a char to another char variable
Subtracting two char variables to compare letters
Converting a float to char
Using char inside a string
Why does the following cause an error?
string s = "He said "Hello" today.";
Because strings cannot contain uppercase letters
Because quotes inside a string must be escaped using "
Because C++ requires single quotes for strings
Because escape sequences cannot appear inside strings
What would be the output of this code and why?
char a = '7';
char b = 7;
cout << a << b;
Both output the character ‘7’ because integers convert to strings
‘7’ followed by a non-printable control character because ASCII 7 is BEL
Two numeric values printed directly
Runtime error due to invalid char assignment
A student writes:
char x = char(65 + 32);
What is the output and why?
‘a’ because ASCII math transforms uppercase letters to lowercase
‘A’ because char() removes addition
65 because char cannot store numerical expressions
Compiler error due to type mismatch
Which reasoning correctly explains why this code prints on two lines?
cout << "HEY\nHEY";
The compiler inserts an automatic newline after every string
'\n' instructs the output stream to create a new line
Strings must always be printed on separate lines
C++ ignores the newline character
What is the most logical reason for grouping escape sequences with the char data type?
Escape sequences represent actions stored as a single encoded character
Escape sequences must always be stored as strings
Escape sequences require more than one byte
Escape sequences contain numbers, not characters
Which BEST explains why this code prints:
cout << int('$');
The compiler converts '$' into its ASCII integer value
Characters cannot be printed directly
Characters are automatically converted to strings
‘$’ has no printable ASCII representation
You need to check whether the char stored is an uppercase letter. Which HOTS reasoning is correct?
Compare it to ASCII range 97–122
Compare it to ASCII range 65–90
Convert the char into a string for comparison
Use escape sequences to detect letter type
What is the reasoning behind using ASCII numeric declarations such as:
It saves memory
It allows characters to be represented without literal symbols
It prevents escape sequence errors
It avoids the need for the char keyword
A student types:
char x = '\t';
cout << "A" << x << "B";
What higher-order explanation describes the spacing effect?
'\t' inserts a horizontal tab, increasing spacing between A and B
'\t' is ignored unless inside loops
'\t' removes characters between A and B
'\t' prints a letter ’t’
Suppose you want to display this output:
He said "Stop!"
Which option shows correct reasoning?
Use single quotes to avoid escape sequences
Escape the inner quotes because they conflict with string delimiters
Avoid using quotation marks inside C++
Insert ASCII values instead of characters
