0

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

1
Contributor
1
Reply
2
Views
4 Years
Discussion Span
Last Post by deanus
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.