Preprocessor Commands

In a previous tutorial, the term "preprocessor commands" was used. Preprocessor commands are... well... commands that come before the program is processed. Preprocessor commands can be recognized by the # sign. In Dev-cpp, they are higlighted as green. In most other C/C++ compilers, they will have some form of highlight. Some preprocessor commands that are useful are...


This preprocessor command copies a file from one location to another, like a .h [header] to a .c file. Used to include prototypes for functions such as printf() and system(). You can find at least one of these in most programs, the most common being #include <stdlib.h>. The syntax is #include then either a < for C standard library functions or " for custom/homemade header functions [prototypes]. There is no semicolon (;) after this command.


This preprocessor command declares a constant. Opposed to a variable, a constant is [usually] a number that, once defined can be used again and again without changing. An example that I use is PI. I go into calc and go 'pi' and it gives me a number; I copy it and paste it after a #define PI like this:

#define PI 3.1415926535897932384626433832795

You can use this for other things, too, such as including header files [more later, explained with section on header files]. No semicolon after this one.


If not defined. Much like an if statement, does what's after it [pre-processor stuff] if what's supplied is not defined. Confusing? Here's an example:

#ifndef PI
#define PI 3.1415926535897932384626433832795

Which brings us up to the next one...


Used to end an if statement. Used after preprocessor if statements, like #ifndef. No semicolon.