Discussion
What will be the value of var for the following C statement?
var = strcmp("Hello", "World");
Answer: A
Correct answer: -1
strcmp compares character by character, and the first pair decides it: 'H' is 72 while 'W' is 87, so the first string sorts before the second and the result is negative. The standard promises only the sign, not the magnitude - some libraries return the difference, here -15 - so code should test < 0 rather than == -1.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development