Semester : S1 and S2
Subject : Computer Programming
Year : 2018
Term : MARCH
Branch : BIOTECHNOLOGY
Scheme : 2015 Full Time
Course Code : CS 100
Page:18
#ifdef-Returns true if this macro is defined.
#ifndef-Returns true if this macro is not defined.
4
5
6 .#if-Tests if a compile time condition is true.
7 #else-The alternative for #if.
8 #elif,#else and #if in one statement.
9 .#endif-Ends preprocessor conditional.
10 .#error-Prints error message on stderr.
11 .#pragma-Issues special commands to the compiler, using 8 standardizedmethod.
Preprocessors Examples
Analyze the following examples to understand various directives.
#define MAX_ARRAY_LENGTH 20
This directive tells the C to replace instances of MAX_ARRAY_LENGTH with 20. Use #define for constants
to increase readability.
೫1೧೦1೮೮
#include "myheader.h"
These directives tell the Compiler to get stdio.h from System Libraries and add the text to the current
source file. The next line tells CPP to get myheader.h from the local directory and add the content to the
current source file.
#undef FILE_SIZE
#define FILE_SIZE 42
It tells the Compiler to undefine existing FILE_SIZE and define it as 42.
#ifndef MESSAGE
#define MESSAGE "You wish!"
84001
It tells the Compiler to define MESSAGE only if MESSAGE isn't already defined.
#ifdef DEBUG
/* Your debugging statements here */
4001
It tells the Compiler to process the statements enclosed if DEBUG is defined. This is useful if you pass the
-DDEBUG flag to the gcc compiler at the time of compilation. This will define DEBUG, so you can turn
debugging on and off on the fly during compilation.
18.a)
A storage class defines the scope (visibility) and life-time of variables and/or functions within a C Program.
They precede the type that they modify. We have four different storage classes ina © program- auto
register static extern
The auto Storage Class
The auto storage class is the default storage class for all local variables.
{