fuddlepixelFuddlepixel coz tech is fun();

Some more PreProcessors

Let us discuss the PreProcessors of the C programming language. How they works before and behind the code to make the coding FUN !

By Shubham Ramdeo
27 November 2015 · 2 mins read
# c  newbie 

Some more PreProcessors

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.

#define

We have already discussed a lot of things about it here.

#include

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.

#undef

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 !


Share this :



Update me weekly ✉

Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.

I'm in ♥


Or follow us
   


About author

Shubham Ramdeo

Shubham Ramdeo

Shubham Ramdeo is the founder of Fuddlepixel. He is a geek, a writer, involved with many technical and humanity projects.

Meet me!



Recent





Related

c 

newbie 

Top