Search This Blog
Sunday, June 3, 2012
Macro Expansions
Macro Expansions
A macro consist of a define directive, a template and a macro expansion.
Eg: #define TOWN “Borella”
#define MAX 212
#define AND &&
During preprocessing the C preprocessor replaces the every occurrence of TOWN in the program
with “Borella”
e.g.
// Alphabetic character count
#include<stdio.h>
#include<conio.h>
#define isalpha(c) ((c>=’a’ && c<=’z’ ) || (c >=’A’ && c <= ‘Z’))
void main()
{
int ch, nc=0;
puts(“Enter a word or a sentence:”)
while (ch = getchar() != ‘\n’)
if (isalpha(ch)) nc++;
printf(“Your word or sentence contains %d alphabetic characters \n”, nc);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment