Hi, I've been using C++ for quite a while but recently I discovered this peculiar behaviour. The following code works as expected:

#define TWO 2;
int nVal = 3 + TWO;
cout<<nVal<<endl;     // output is 5

...if on the other hand I place the literal integer after the '+' in the expression, the '+ 3' is ignored.

#define TWO 2;
int nVal = TWO + 3;
cout<<nVal<<endl;     // output is 2, instead of 5

Is there any reason for this behaviour? I'm using Microsoft Visual C++ 2010 Express on Windows 7 32-bit.

Thanks,
Dean

Wow, I can't believe I didn't notice the semi-colon at the end of the preprocessor definition. Sorry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.