1 / 5
Apr 2012

I am not sure if this is the right place to ask this question but i am desperate to know the answer. I possibly couldn't figure out the output here.

#include <stdio.h>
#define sqr(b) b*b
int main()
{
        int a;
        scanf("%d",&a);
        printf("%d",sqr(a+3));
        return 0;
}

Any help or tutorial regarding such type of examples will be appreciated.

Yes i did execute but i am unable to understand the output which the program is executing. Couldn't possibly get it.

acc. to me

for a = 2, Output should be 25 but the correct output is 11 exclamation

It makes complete sense. A macro does what you tell it to do, and only exactly what you tell it to do.

The macro replaces:

sqr(a+3)

With:

a+3*a+3

If you want 25 then you need to add some brackets to your macro.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 14 6d

Want to read more? Browse other topics in C and C++ or view latest topics.