Programming in C

(Barry) #1
The #defineStatement 301

else
answer = NO;

return answer;
}


int main (void)
{
int isEven (int number);


if ( isEven (17) == YES )
printf ("yes ");
else
printf ("no ");

if ( isEven (20) == YES )
printf ("yes\n");
else
printf ("no\n");

return 0;
}


Program 13.1 Output


no yes


The #definestatements appear first in the program.This is not required; they can appear
anywherein the program.What is required is that a name be defined before it is refer-
enced by the program. Defined names do not behave like variables:There is no such
thing as a local define. After a name has been defined in a program, either inside or out-
side a function, it can subsequently be used anywherein the program. Most programmers
group their defines at the beginning of the program (or inside an includefile^1 ) where
they can be quickly referenced and shared by more than one source file.
The defined name NULLis frequently used by programmers to represent the null
pointer.^2


Program 13.1 Continued



  1. Read on to learn how defines can be set up inside special files that you can include in your
    program.
    2.NULLis already defined on your system inside a file named <stddef.h>. Again, include files are
    discussed in more detail shortly.

Free download pdf