Question #43348

what do you mean by "if(!strcmp(subject, index))" i get from this segment of code and i didnt get what does the ! really does
char name[ ] = "a";
char profession[ ] = "b";
char subject[ ] = "c";
cout << "please enter a word to search: ";
cin >> index;
if(!strcmp(name, index))
cout << "first letter" <<endl;
else
if(!strcmp(profession, index))
cout << "second letter" << endl;
else
if(!strcmp(subject, index))
cout << "third letter" << endl;

Expert's answer

strcmp function returns 0 if the strings are equal. Computer &quot;thinks&quot; that everything that is not zero is true, and zero is false.
So the line which confused you is read as &quot;if not strcmp(name, index) equals true&quot; or &quot;if(strcmp(profession, index) == 0)&quot;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS