Here is a listing of C test questions on “Character Class Testing & Conversions” along with answers, explanations and/or solutions:
1. Which of the following library function is not case-sensitive?
a) toupper()
b) tolower()
c) isdigit()
d) all of the mentioned
Answer: c
Clarification: None.
2. The following C expression can be substituted for?
if (isalpha(c) && isdigit(c))
a) if (isalnum(c))
b) if (isalphanum(c))
c) if (isalphanumeric(c))
d) none of the mentioned
Answer: d
Clarification: None.
3. Which of the following will return a non-zero value when checked with isspace(c)?
a) blank
b) newline
c) return
d) all of the mentioned
Answer: d
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
#include
-
int main()
-
{
-
char i = 9;
-
if (isdigit(i))
-
printf("digitn");
-
else
-
printf("not digitn");
-
return 0;
-
}
a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned
Answer: b
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
#include
-
int main()
-
{
-
int i = 9;
-
if (isdigit(i))
-
printf("digitn");
-
else
-
printf("not digitn");
-
return 0;
-
}
a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned
Answer: b
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
char i = '9';
-
if (isdigit(i))
-
printf("digitn");
-
else
-
printf("not digitn");
-
return 0;
-
}
a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned
Answer: a
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
#include
-
int main()
-
{
-
int i = 0;
-
if (isspace(i))
-
printf("spacen");
-
else
-
printf("not spacen");
-
return 0;
-
}
a) Compile time error
b) space
c) not space
d) None of the mentioned
Answer: c
Clarification: The value of variable i is 0 which is the NULL character in ASCII. Hence, the output will be printed as “not space”.
8. What will be the output of the following C code?
-
#include
-
#include
-
int main()
-
{
-
int i = 32;
-
if (isspace(i))
-
printf("spacen");
-
else
-
printf("not spacen");
-
return 0;
-
}
a) Compile time error
b) space
c) not space
d) None of the mentioned
Answer: b
Clarification: The ASCII value of space character is 32. Since the variable i stores 32, the output will be printed as “space”.