What #include, #define and others really do in your C Program

What #include, #define and others really do in your C Program

A good majority of programmers (especially beginners) when starting in learning about the C language, often find it hard to understand essential concepts required for every C program to function correctly. This is not only experienced in the Compiled language alone as it cut across every programming language. The practice of not understanding primary concepts while learning anything is very unhealthy because you will find it hard to understand bigger concepts related to such topic flow.

There are many concepts to know in the C programming language but in this article, I will try my best in explaining why we use statements such as #include <> at the beginning of the C programming language.

What is '#' and its function in C

You must have come across this # symbol while understanding how the C program works and must have used it while writing programs that print something in C or when defining macros in the program but did not fully understand why we had to include that specific symbol in the C program especially at the beginning. Well, let me break it down to the best of my knowledge.

The "#" symbol known as "the Pound Sign" or "Hash Symbol", is used to give special instructions in C language at the beginning of most C programs, especially when giving directives to the preprocessor. It is used to instruct the preprocessor to carry out certain functions such as: including header files, defining macros, and performing conditional compilations before the proper compilation of the program begins, and so Before the compiler compiles any program, the program first looks out for the availability of the hash symbol to discover if there are instructions to be carried out by the preprocessor before compilation. If there are any, the preprocessor performs all actions required by these special instructions and then the compiler proceeds with its compilation.

We must ascertain that without the "#" symbol, the program will not understand that the instructions are meant to be carried out by the preprocessor, keep that in mind.

Preprocessor Commands

At the beginning of this little journey, I mentioned "Understanding of Concepts" and made mention of code statements like #include <> Now this statement alongside other statements such as #define, #ifdef, #error, #undef, etc are all directives or instructions that are written for the preprocessor to carry out, for example, the #include <stdio.h>statement simply tells the preprocessor to include a standard input and output library in the program to enable it to understand certain function statements that are in that particular library whenever they are used in the source code. Without this particular library, you will not be able to use functions like printf or scanf in your program. Here's a scenario, when trying to understand a topic or even write about it, we make research it online or in books to understand better, we also return to those resources when we forget something or get stuck. A similar thing happens when we write the #include <stdio.h> in our C code. The program utilizes the standard input and output library as a reference to understand what it is supposed to do when it comes across function statements like printf(), putchar(), etc.

Wrap-up

There is a lot more to know and learn in the C programming language and I believe by reading this, you have been able to understand the whats and whys of using the hash symbol when writing C programs and that we need # to enable us to define directives for the preprocessor.

I appreciate that you were able to read this all through to the end, and I hope this has helped better your understanding of the C programming language. Please feel free to share this with your friends, colleagues, and communities if you found it helpful and enjoyable. Also, feel free to share your feedback with me and I will also appreciate suggestions about content you will like to see here in the future. Do not forget to follow me also to stay up-to-date with future articles and updates.

Until next time, Enjoy learning! Enjoy coding!