LearnFrenzy
Sign in Take a free test

Decision Making · Decision Making MCQ · Question 5

Correct condition to check if a string equals "admin" Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

Which condition checks whether the string role equals "admin"?

  • A role == "admin"
  • B strcmp(role, "admin") == 0 Correct
  • C strcmp(role, "admin")
  • D *role == "admin"
Correct Answer: Option B

== compares addresses. strcmp() returns 0 when the strings are equal – so the bare call is true when they differ, a classic mistake.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links