Thursday, December 13, 2007

Another C Program...

My friend asked me to check this program out.
I learnt something new trying it out.
Hope you learn something too.

PROGRAM:

#define square(x) x*x
#include
int main()
{
int x;
x=5;
char *p;
p="%d\n";
printf(p,100);
char *w[]={"Kct","yahoo","google"};
printf("%s",*w+4);
printf("\n%d",square(x));
printf("\n%d",square(x+1));
printf("\n%d",square(++x));
getchar();
return 0;
}

OUTPUT:
100
yahoo
25
11
49

*The output is from Dev c++ compiler.

2 comments:

Rajarshi said...

Y dont u use C++ instd of C.Nd wat did u learn from this.I mean it luks okay with all pointers and all....

Deepak said...

c or c++ look at what i the programz application is....
check the harmless statement...
#define square(x) x*x

but if use a stament like
square(x+1)
it is taken as x+1*x+1
and not (x+1)*(x+1)
so it is better to use #define statements with brackets

#define square(x) (x)*(x)
is correct..