Programming in C: Defines and Includes

Includes

In a previous tutorial we looked briefly at includes, but now we will go in-depth. An include statement, like the one we saw in the first program we wrote, are necessary for using certain built in C functions. To remind you, the first include statement we used was:

#include <stdio.h>

The standard input-output header file is needed for definitions of certain functions, like printf. The preprocessor replaces with file contents, then it compiles them. More on preprocessor-time, compile-time, link-time and run-time errors in a later tutorial.

#include <stdlib.h>

The standard library header file is needed for definitions of other functions like exit, which we will see below.

Define

A standard definition statement looks like:

#define NAME VALUE

During preprocessor time it replaces all 'NAME' with 'VALUE' before compile time. This allows for easy global changes, readability and faster execution. Here is an example program using a definition statement. Leave a comment below with the correct output of the following program:

#include <stdio.h>
#include <stdlib.h>

#define NUMBER 723

int main(void) 
{
printf("The number is %d\n", NUMBER);
exit(0);
}

More tutorials coming soon! Let me know how you like the tutorials by commenting below and if there is any specific topics or languages you would like covered.

Programming in C: Modifiers

Programming Using C: Variables and printf