Changes between Version 42 and Version 43 of ResumedC
- Timestamp:
- Sep 9, 2009, 5:23:55 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ResumedC
v42 v43 17 17 {{{ 18 18 #!C 19 /* Wrong way: */19 /* Wrong way: */ 20 20 if (strcmp(string1, string2)) 21 ... 22 23 /* Easy-to-understand way: */ 21 /* Easy-to-understand way: */ 24 22 if ((strcmp(string1, string2) == 0) 25 ... 26 }}} 23 24 /* Wrong way: */ 25 long *pTab[10]; // It creates an array with 10 pointers to the type long 26 /* Easy-to-understand way: */ 27 long (*pTab)[10]; // It creates a pointer to an array with 10 elements in type long 28 }}} 29 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. 31 32 '''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. 27 33 28 34 By separating the source code in multiple files, you have your code a lot more organized and there's a lot more easy to read and specially to search something between the code. … … 221 227 struct time lap[MAX_LAPS]; 222 228 /* This call creates an array called 'lap' of MAX_LAPS elements that are structures of type 'time' */ 229 struct time t1, t2, *pLap, lap[100]; 230 /* Different methods to create structures */ 223 231 224 232 /* You can also set values like */ … … 286 294 pa = a; // pa points to a[0] 287 295 288 /* array of 5 elements */296 /* array of 5 elements */ 289 297 char arr[5]; 290 298 291 /* pointer 'arr_p' to the array 'arr' */299 /* pointer 'arr_p' to the array 'arr' */ 292 300 char *arr_p = &arr[0]; 293 294 *(array_p + 1) /* Equivalent */ 295 (*array_p + 1 ) /* Not Equivalent */ 301 *(array_p + 1) // Equivalent 302 (*array_p + 1 ) // Not Equivalent 303 304 /* All these methods are equivalent: */ 305 &a[i] , a+i , pa+i , &(pa[i]) // Pointers to the 'i' element of an array 306 a[i] , *(a+i) , *(pa+i) , pa[i] // In the same method way, the 'i' element of an array (no-pointer) 296 307 }}} 297 308