These are the Preprocessors of C language that can be used to make programming FUN !
Welcome to Newbie Programmer Series. In the last post (click here) We have discussed a preprocessor called #define. In this post, we will discuss some more of them. Well, this series is made for those who are absolutely new in the programming world. So to keep everything simple and easy, I would not go too deep into the language features. But to introduce you, I am discussing below some more preprocessors that you will find while reading some sources of C programs. So if you are new to this series, please go to index (click here) and read out all the previous parts so that you can easily understand what I am discussing below.
We have already discussed a lot of things about it here.
This preprocessor is used to include the files while building the program. And we are already used to with it. As before any program that is using “printf”, we include the “stdio.h” file.
Its usage is simple :
If you want to use the standard files of C (system libraries) which are placed somewhere in C’s folder like stdio.h you can use :
#include < filename >
Or if you want to use a file,
#include "filename in the source file directory"
Its like suppose you have a function in some file “xyz.c” and you want to use that function in your current file, just add => #include “xyz.c” And then you can use that function from xyz.c file to your current one. But don’t worry we will discuss this later in detail.
In C language, there are MAY BE many things which are already defined. This #undef is used to remove that definition. Like in some of your code you have added :
#define PI 3.14
In some file, you want to use PI as 3 only. And this change is to be made in a particular file only. Then you can do something like this :
#undef PI //this will remove its value #define PI 3 //redefining new value
#ifdef #ifndef #endif
You can also use some conditional statements with preprocessing. like this :
Suppose you want to make a PI definition ONLY IF its not already defined, then :
#ifndef PI #define PI 3.14 #endif
Suppose you want to change the value of PI only if its already defined.
#ifdef PI #undef PI #define PI 3 #endif
You can use #else and #elif as well but we will discuss it later. This post look small but
I will update this post and add the other ones later once we do some applications.
Because that will make this over complicated as we are very new. So we need to do some applications. In the next post, we will do some great application to learn how beautiful preprocessors are !