Changes between Version 54 and Version 55 of ResumedC


Ignore:
Timestamp:
09/24/12 17:09:45 (5 years ago)
Author:
thanatermesis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ResumedC

    v54 v55  
    1919   /* Wrong way: */ 
    2020if (strcmp(string1, string2)) 
     21    printf("......"); 
    2122   /* Easy-to-understand way: */ 
    22 if ((strcmp(string1, string2) != 0) 
     23if (strcmp(string1, string2) == 0) 
     24    printf("Strings equal"); 
    2325 
    2426   /* Wrong way: */ 
     
    2830}}} 
    2931 
    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. 
     32Why 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. 
    3133 
    3234'''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.