Changes between Version 54 and Version 55 of ResumedC
- Timestamp:
- Sep 24, 2012, 5:09:45 PM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ResumedC
v54 v55 19 19 /* Wrong way: */ 20 20 if (strcmp(string1, string2)) 21 printf("......"); 21 22 /* Easy-to-understand way: */ 22 if ((strcmp(string1, string2) != 0) 23 if (strcmp(string1, string2) == 0) 24 printf("Strings equal"); 23 25 24 26 /* Wrong way: */ … … 28 30 }}} 29 31 30 Note that using this way, not only your code is better to read but also a lot less error-prone specially for you, and for who needs to modify it, so that the program will do something different at what you are waiting to do, or that who reads it will think that it does something when is doing another thing.32 Why the first example is a more ''wrong way'' than the second? because the common sense makes the reader to think that the printf will be run when the sentences are equal, but what exactly happens is that will return 0 if they are equal so the printf will be not run, this is more clear to understand with the second example. 31 33 32 34 '''Tip''': Apart of that is more easy to read and less error-prone the method of using parentheses, in order to made your code clear and/or if you don't know the order of on which order the things are called in a line, use parentheses.