Tutorial by Examples

foo.h #ifndef FOO_DOT_H /* This is an "include guard" */ #define FOO_DOT_H /* prevents the file from being included twice. */ /* Including a header file twice causes all kinds */ /* of interesting problems.*/ /** * This is a functi...
Use of global variables is generally discouraged. It makes your program more difficult to understand, and harder to debug. But sometimes using a global variable is acceptable. global.h #ifndef GLOBAL_DOT_H /* This is an "include guard" */ #define GLOBAL_DOT_H /** * This tells ...
Headers may be used to declare globally used read-only resources, like string tables for example. Declare those in a separate header which gets included by any file ("Translation Unit") which wants to make use of them. It's handy to use the same header to declare a related enumeration to ...
Example of declarations are: int a; /* declaring single identifier of type int */ The above declaration declares single identifier named a which refers to some object with int type. int a1, b1; /* declaring 2 identifiers of type int */ The second declaration declares 2 identifiers named a1 a...
Typedefs are declarations which have the keyword typedef in front and before the type. E.g.: typedef int (*(*t0)())[5]; (you can technically put the typedef after the type too - like this int typedef (*(*t0)())[5]; but this is discouraged) The above declarations declares an identifier for a typ...
The "right-left" rule is a completely regular rule for deciphering C declarations. It can also be useful in creating them. Read the symbols as you encounter them in the declaration... * as "pointer to" - always on the left side [] as "array of" ...

Page 1 of 1