Showing posts with label preprocessor directives c. Show all posts
Showing posts with label preprocessor directives c. Show all posts

Thursday, 17 October 2013

Preprocessor Directives In C

Preprocessor directives in C:

In C++, we don’t have large number of operations. Only small number of operation like arithmetic and assignment operations are available. But to run a C++ program many type of functions are required. C++ has a collection of libraries. We use them to get access to many interesting and important operations. Every library has a unique name and is referred to by a header file.

Examples:

The function needed to perform input/output (I/O) are contained in the header file iostream.
For performing useful mathematical operations like power, absolute and sine, we use a header file named cmath
If you want to use these functions, you need to tell the computer where to find the necessary code as you know computer is dumb. You use c pre-processor directives and the names of header files to tell the computer the locations of the code provided in libraries.
Preprocessor directives c
are commands supplied to the preprocessor that cause the preprocessor to modify the text of a C++ program before it is compiled. All preprocessor commands begin with #.

Syntax:

#include <header file name>

Example:

  • #include<iostream>
  • #include<cmath>


Note: These headerfiles are defined at the start so that you can use them throughout the program.



Namespace:

In earlier tutorials, we learnt about cin and cout. These functions are defined in iostream but within a namespace. The name of this namespace is std. We’ll discuss the namespace in detail in further tutorials. For now, we’ll stick to basics.

We declare it by writing:

using namespace std;

If we don’t use it then every time we have to introduce cout and cin like the one defined below throughout the program.
std::cin
std::cout

Final Words:

Preprocessor directives in c are very important.Without them the programming must have been very difficult.In this c tutorial for beginners we discussed them in detail so that our viewers can understand them easily.