C Programming Questions and Answers – Character Class Testing & Conversions – 1

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Character Class Testing & Conversions – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

1. Which of the following library function is not case-sensitive?
a) toupper()
b) tolower()
c) isdigit()
d) all of the mentioned
View Answer

Answer: c
Explanation: None.

2. The following C expression can be substituted for?

advertisement
advertisement
 if (isalpha(c) && isdigit(c))

a) if (isalnum(c))
b) if (isalphanum(c))
c) if (isalphanumeric(c))
d) none of the mentioned
View Answer

Answer: d
Explanation: None.
advertisement

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
View Answer

Answer: d
Explanation: None.

4. What will be the output of the following C code?

advertisement
  1.     #include <stdio.h>
  2.     #include <ctype.h>
  3.     int main()
  4.     {
  5.         char i = 9;
  6.         if (isdigit(i))
  7.             printf("digit\n");
  8.         else
  9.             printf("not digit\n");
  10.             return 0;
  11.     }

a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned
View Answer

Answer: b
Explanation: None.
advertisement

5. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     #include <ctype.h>
  3.     int main()
  4.     {
  5.         int i = 9;
  6.         if (isdigit(i))
  7.             printf("digit\n");
  8.         else
  9.             printf("not digit\n");
  10.             return 0;
  11.     }

a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned
View Answer

Answer: b
Explanation: None.

6. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char i = '9';
  5.         if (isdigit(i))
  6.             printf("digit\n");
  7.         else
  8.             printf("not digit\n");
  9.             return 0;
  10.     }

a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

7. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     #include <ctype.h>
  3.     int main()
  4.     {
  5.         int i = 0;
  6.         if (isspace(i))
  7.             printf("space\n");
  8.         else
  9.             printf("not space\n");
  10.             return 0;
  11.     }

a) Compile time error
b) space
c) not space
d) None of the mentioned
View Answer

Answer: c
Explanation: 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?

  1.     #include <stdio.h>
  2.     #include <ctype.h>
  3.     int main()
  4.     {
  5.         int i = 32;
  6.         if (isspace(i))
  7.             printf("space\n");
  8.         else
  9.             printf("not space\n");
  10.             return 0;
  11.     }

a) Compile time error
b) space
c) not space
d) None of the mentioned
View Answer

Answer: b
Explanation: The ASCII value of space character is 32. Since the variable i stores 32, the output will be printed as “space”.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.