Preprocessor Directives II-267
Find the bug/s in the following programs.
1.
#include <stdio.h>
#define 3.14 PI
void main()
{
printf("%f",PI);
}
Bug: The statement defining macro should be # define PI 3.14
2.
#include <stdio.h>
#define DOUBLE(a) a*2# define TRIPLE(a) a*3
void main()
{ int a=1;
clrscr();
for(;a<=5;a++)
printf(" %d %d %d",a,double(a), TRIPLE(a));
}
Bug: The macro DOUBLE is typed as double
3.
#include <stdio.h>
#define wait getche()
void main()
{
int k;#undef wait()
getche();
clrscr();
for(k=1;k<5;k++)
printf(" %d ",k);wait;}
Bug: The macro wait is undefined
M12_ITL-ESL4791_02_SE_C12.indd 267 12/22/2012 5:05:49 PM
II-268 Programming Concepts
4.
#include <stdio.h>
#define say(m) printf(m)
#define show(m) printf(#m)
void main()
{
clrscr();
say(Hello);
show(Hello);
}
Bug: The text Hello should be enclosed in double quotes in say macro
5.
#include <stdio.h>
#define T 8
void main()
{
clrscr();
#ifndef T
printf(" Macro is not defined");
#else
printf(" Macro is defined");
}
Bug: #endif is missing
M12_ITL-ESL4791_02_SE_C12.indd 268 12/22/2012 5:05:49 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset