Go to top
KB01 - C Programming Styles
- Include the followings and all other related header files in all your program.
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <stdbool.h>
- Declare functions and variables before using them.
- Better to increment and decrement with ++ and -- operators.
- Better to use x += 5 instead of x = x + 5
- A string is an array of characters ending with a ‘\0”. Don’t ever forget the NULL character
- An array of size n has indices from 0 to n-1. Although C will allow you to access A[n] it is very
- A character can be represented by an integer (ASCII value) and can be used as such
- The unary operator & produces an address
- The unary operator * dereference a pointer
- Arguments to functions are always passed by value. But the argument can be an address of just
- For efficiency, pointers can be passed to or returned from a function
- Logical false is zero and anything else is true
- You can do things like for(;;) or while(i++) for program efficiency and understanding
- Use /* .. */ instead of //, it makes the code look better and readable
- The last and most important one is always compiling your program before submitting or showing it to someone. Don’t assume that your code is compliable and contains no errors. Try using –std=c99,
which is c99 standard. It is better. (Although, c11 is also on its way but is not a standard at the moment for all machines)