The Preprocessor directives

A preprocessor is a program that processes a source file before the main compilation takes place. The C language handles directives whose names begin with a number sign #. We don’t need to do anything special to invoke this preprocessor. It is invoked automatically by the compiler when we compile the program.

The #include directive tells the compiler to include a different source-code file in your program. This directive tells the compiler to add the contents of the stdio.h file into your source file. This action of preprocessor is similar to pasting a block of text data into a document with your word processor.

Now the question arises – why add the contents of the stdio.h file to the program? Actually the stdio.h describes some functions that are used for console input/output because the C language does not provide any such facility of reading/writing directly on the console. The stdio.h stands for standard input–output and ‘.h’ stands for header file. By input we mean the information brought into the program and output sends out the information from the program. We can receive information either from a standard input device, keyboard, or from a file. Similarly we can send information either to a standard output device, VDU, or to a file.

The stdio.h provides scanf() function to receive information from a standard input device and printf() function to send information to a standard output device. That’s why it is necessary for the programs that use scanf() and printf() functions for input and output, to include the stdio.h file. Without its inclusion, the compiler would not recognize scanf() and printf() functions. However in some compilers, the inclusion of header files are optional. But in other compilers, it is necessary. Remember that files with .h extension are referred as header files.

The filename in the #include directive is enclosed by angle brackets, that is ‘’ (greater than symbol). This usage identifies header files that compiler system provides. However if you want to include your own header files then you would surround these user-defined header files within double quotes (“….”) as:

#include “userfile.h”
Here userfile.h is an user-defined header file.

The function main()

Every C program must have a main() function. The word main is followed by a pair of ordinary parentheses ‘(’ and ‘)’. Here you can not use square brackets ‘[’ and ‘]’ or even curly braces ‘{’ and ‘}’. There is nothing enclosed in the parentheses because the main function does not have any parameters. The word main() is followed by the statement(s) enclosed within the curly braces ‘{’ and ‘}’. However in C, the curly braces, along with the statements enclosed within them are referred to as a compound statement.

In some programs you may also find the following notations for main() function:

(i)    void main()
(ii)   void main(void)
(iii)  int main()

Actually the part that precedes the function main is called the function return type. The word void that precedes the function main in first and second notations specifies that this function does not return any value to the caller. Similarly the word that follows the main in second notation specifies that this function receives no argument from the function that calls it. Now look at the third notation. This third notation specifies that this function returns an int value. Therefore you have to place a return statement before the closing brace of main() function as:

….
int main()
{
….
return 1;
}

Finally one may ask you – who calls main() function? It is not you (although in fact you can call main() if you want, just as you can call other functions); but it is the startup code who is the primary customer for main() function.

The printf() Function

The printf() function is used to display a message enclosed between the double quotes, to the monitor. It is the most important function used to display text on the screen. Like any function, the printf() function has two parentheses between which comes the string to be displayed, enclosed in double quotations.

Here the printf() function is embedded into a statement whose ending is marked by the semicolon (;). Note that every statement in C is terminated by a semicolon (;). In other words, you can say that the semicolon tells the compiler that a statement is terminated. Now look at the strange character ‘\n’ that comes right after the string and before ending the double quote mark. This character is called new-line character. This new-line character (\n) brings the cursor to the beginning of the next line.


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet

Which part of your face you like the most?

Choose from the options which part of your face you think as very beautiful.
No answer selected. Please try again.
Please select either existing option or enter your own, however not both.
Please select minimum 0 answer(s) and maximum 8 answer(s).
/polls/family-and-home/5951-which-part-of-your-face-you-like-the-most.json?task=poll.vote
5951
checkbox
[{"id":"20499","title":"Eyes","votes":"38","type":"x","order":"0","pct":33.04,"resources":[]},{"id":"20500","title":"Nose","votes":"12","type":"x","order":"0","pct":10.43,"resources":[]},{"id":"20501","title":"Lips","votes":"15","type":"x","order":"0","pct":13.04,"resources":[]},{"id":"20502","title":"Forehead","votes":"4","type":"x","order":"0","pct":3.48,"resources":[]},{"id":"20503","title":"Cheeks","votes":"9","type":"x","order":"0","pct":7.83,"resources":[]},{"id":"20504","title":"All of them","votes":"30","type":"x","order":"0","pct":26.09,"resources":[]},{"id":"20505","title":"None","votes":"4","type":"x","order":"0","pct":3.48,"resources":[]},{"id":"20506","title":"other(specify)","votes":"3","type":"x","order":"0","pct":2.61,"resources":[]}] ["#ff5b00","#4ac0f2","#b80028","#eef66c","#60bb22","#b96a9a","#62c2cc"] ["rgba(255,91,0,0.7)","rgba(74,192,242,0.7)","rgba(184,0,40,0.7)","rgba(238,246,108,0.7)","rgba(96,187,34,0.7)","rgba(185,106,154,0.7)","rgba(98,194,204,0.7)"] 350
bottom 200
No married couple wants to end up getting divorced. It is not like they have planned for it. They try to put up with their partners for as long as they
Due to our modern lifestyle, we feel that digestion related disorders are a common problem. Thus, we neither give importance to them nor seek any help
The bond of marriage brings the two people together. Initially, everything may seem okay and both of them slowly start discovering each other in the journey.
Class is a key feature in C++. It makes programming much easier. To implement the class we need to create objects for that class. So, let's start with
DYNAMIC MEMORY ALLOCATION: Dynamic memory allocation is the means by which a program can obtain memory while it is running. Global variables are allocated
This is a technique to sort a given array in an acending order. Here is the steps we follow while performing quick sort :- The last element of array
When objects are declared that is constructed for a particular class then this objects will occupy certain memory locations. The data members of these
Develop a class to represent complex number. The class should have following member function. A fn to get the CN from user. A fn to display the CN A