Find the output of the following c program.
1.#include<stdio.h>
#define MAX 5;
int main()
{
printf("%d",MAX);
return
0;
}
2.#include<stdio.h>
#define MSSG printf("Practice makes you
different\n");
int main()
{
MSSG
return
0;
}
3.#include<stdio.h>
#define PROD(x,y) x*y
int main()
{
int a;
a=PROD(2+3,3+2);
printf("Product=%d",a);
return 0;
}
4.#include<stdio.h>
#define PROD(x,y) ((x)*(y))
int main()
{
int a=2+2, b=3;
printf("Product=%d",PROD(a,b));
return 0;
}
5.#include<stdio.h>
#define A 5
#define B A+10
int main()
{
int i,j;
i=B/3;
j=15-B;
printf("i=%d,j=%d\n",i,j);
return 0;
}
6.#include<stdio.h>
#define NEW_LINE printf("\n");
#define BLANK_LINES(n) {int i;
for(i=0;i<n;i++) printf("\n");}
int main()
{
printf ("When you have a chance");
NEW_LINE
printf ("to motivate someone") ;
BLANK_LINES(2)
printf("Give it a big hug");
NEW_LINE
return 0;
}
7.#include<stdio.h>
#define INFINITE while(1)
#define CHECK(a) if(a==0) break
int main()
{
int x=5;
INFINITE
{
printf
("%d ",x--) ;
CHECK(x);
}
return 0;
}
8.#include<stdio.h>
#define ABS(x) ((x)<0?(x):(x))
int main()
{
int
array[4]={1,-2,3,-4};
int
*p=array+3 ;
while
(p>=array)
{
printf("%d ",ABS(*p));
p--;
}
return
0;
}
9.#include<stdio.h>
#define . ;
int main()
{
printf("If the lift to success is
broken, ").
printf("Try the stairs.").
return 0;
}
10.#include<stdio.h>
#define CUBE(x) (x*x*x)
int main()
{
printf("%d\n",CUBE(1+2));
return
0;
}
11.#include<stdio.h>
#define SQ(x) ((x)*(x))
int main()
{
int i=1;
while (i<=8)
printf("%d ",SQ(i++));
return 0;
}
12.#include<stdio.h>
#define SWAP(dtype,x,y) {dtype t; t=x+y,
x=t-x, y=t-y;}
int main()
{
int
a=1, b=2, x=3, y=4, s=5, t=6 ;
SWAP(int,a,b)
SWAP(int,x,y)
SWAP(int,s,t)
printf("a=%d,b=%d,x=%d,y=%d,s=%d,t=%d\n",a,b,x,y,s,t);
return
0;
}
13.#include<stdio.h>
#define INC(dtype,x,i) x=x+i
int main()
{
int arr[5]={2,3,5,1,9},*ptr=arr;
INC(int,arr[2],3);
INC(int*,ptr,2);
printf("*ptr=%d\n",*ptr);
return 0;
}
14.#include<stdio.h>
#define INT int
int main()
{
INT a=2, *p=&a;
printf("%d %d \n",a,*p);
return 0;
}
15.#include<stdio.h>
#define Y 10
int main()
{
#if X || Y && Z
printf ("Sea in Depth\n");
#else
printf("See in depth\n");
#endif
return 0;
}
16.#include<stdio.h>
int main()
{
int
x=3,y=4,z;
z=x+y;
#include<string.h>
printf("%d\n",z) ;
return
0;
}
17.#include<stdio.h>
#define MAX 3
int main( )
{
printf ("MAX=%d\n" ,MAX);
#undef MAX
#ifdef MAX
printf("Have a good day");
#endif
return 0;
}
18.#include<stdio.h>
#define PRINT(message)
printf("faith") ;
int main()
{
PRINT("Don't
neglect love\n")
return
0;
}
19.#include<stdio.h>
#define PRINT(message) printf (#message);
int main()
{
PRINT("If
we rest, we rust.\n")
return
0;
}
20.#include<stdio.h>
#define show(value)
printf(#value"=%d\n",value);
int main()
{
int a=10,b=5,c=4;
show(a/b*c);
return 0;
}
21.#include<stdio.h>
#define MACRO(a) if(a<=5)
printf(#a"=%d\n”,a);
int main()
{
int
x=6,y=15;
if
(x<=y)
MACRO(x);
else
MACRO(y);
return
0;
}
22.#include<stdio.h>
int main()
{
#line
100 "pro.c"
printf
("%d %s\n",__LINE__,__FILE__);
return
0;
}
ANSWER
1.
compilation
error
2. Practice makes you different
3. 13
4. 12
5. i=8,j=20
6. When you have a chance
to
motivate someone
Give
it a big hug
7. 5 4 3 2 1
8. -4 3 -2 1
9. compilation error
10. 7
11. 2
12 30 56
12. a=2,b=1,x=4,y=3,s=0,t=6
13. *ptr=8
14. 2 2
15. See in depth
16. 7
17. MAX=3
18. faith
19. "If we rest, we rust.\n"
20. a/b*c=8
21. compilation error
22. 100 pro.c
No comments:
Post a Comment
For any doubt or suggestion you can write here