In the C Programming Language, the #ifndef directive checks if the given token has been #defined earlier in the C code. If the token has not been defined earlier then it includes the code between #ifndef and #else. If no #else is present then code between #ifndef and #endif is included.

The #ifndef and #define are known as header guards. They are used to prevent header files from being included multiple times.

#ifndef and #define

The syntax of using #ifndef is as below:

Use of #ifndef and #define

Here is a rather complete C program to demonstrate the use of #ifndef and #define.

The output of the above program is:

Here is a another C program to demonstrate the use of #ifndef and #define. As INTEREST_RATE is already defined so #ifndef does not execute.

The output of the above program is: