C++ interview questions and answers focuses on “Character Types”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ interview questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.
C++ questions on “Character Types” along with answers, explanations and/or solutions:
Q 1. How many characters are specified in the ASCII scheme?
A. 24
B. 64
C. 128
D. 256
Show Answer
Answer:-C. 128Explanation
here are 128 characters defined in the C++ ASCII list.Q 2. Which of the following belongs to the set of character types?
A. char
B. wchar_t
C. only a
D. both wchar_t and char
Show Answer
Answer:-D. both wchar_t and charExplanation
wchar_t and char are used to represent wide character and character.Q 3. Given the variables p, q are of char type and r, s, t are of int type. Select the right statement?
1. t = (r * s) / (r + s); 2. t = (p * q) / (r + s);
A. 1 is true but 2 is false
B. 1 is false and 2 is true
C. both 1 and 2 are true
D. both 1 and 2 are false
Show Answer
Answer:-C. both 1 and 2 are trueExplanation
Every character constant has an integer value. Also char belongs to the integral type hence arithmetic and logical operations can be performed on them.Q 4. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
char c = 74;
cout << c;
return 0;
}
A. A
B. N
C. J
D. I
Show Answer
Answer:-C. JExplanation
The literal value for 74 is J. So it will be printing J.Q 5. What will be the output of the following C++ code?
#include <stdio.h>
int main()
{
char a = ‘\012‘;
printf(“%d”, a);
return 0;
}
A. Compiler error
B. 12
C. 10
D. Empty
Show Answer
Answer:-C. 10Explanation
The value ‘\012’ means the character with value 12 in octal, which is decimal 10.Q 6. How do we represent a wide character of the form wchar_t?
A. L’a’
B. l’a’
C. L[a]
D. la
Show Answer
Answer:-A. L’a’Explanation
A wide character is always indicated by immediately preceding the character literal by an L.Q 7. Is the size of character literals different in C and C++?
A. Implementation defined
B. Yes, they are different
C. Can’t say
D. No, they are not different
Show Answer
Answer:-B. Yes, they are differentExplanation
In C++, sizeof(‘a’) == sizeof(char) == 1. In C however, sizeof(‘a’) == sizeof(int).Q 8. In C++, what is the sign of character data type by default?
A. Signed
B. Unsigned
C. Implementation dependent
D. Unsigned Implementation
Show Answer
Answer:-C. Implementation dependentExplanation
The standard does not specify if plain char is signed or unsigned. There are three distinct character types according to the standard: char, signed char and unsigned char.Q 9. What constant defined in <climits> header returns the number of bits in a char?
A. CHAR_BIT
B. SIZE_CHAR
C. BIT_CHAR
D. CHAR_SIZE
Show Answer
Answer:-A. CHAR_BITExplanation
CHAR_BIT is a macro constant defined inQ 10. Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char) return?
A. 4
B. 1
C. Implementation dependent
D. Machine dependent
Leave a Reply