Tuesday, December 21, 2010

#include"problem1.h"

#include<iostream.h>

#define SQUARE(x) x*x

inline int square(int a)
{
    return a*a;
}

void main()
{
    int a=3,b=3;
        cout<<SQUARE(++a)<<endl<<square(++b);
}
Output:
20
16

Explanation:
SQUARE(++a) : ++a*++a
These are the side effects of macro.The increment operator is specified once but it is incremented twice.Such side effects would not occur in functions.

1 comment: