I don’t understand why the result is going to be 36. Can somebody explain to me what is happening here and what the preprocessor does?
#include <iostream>
#define QUADRAT(x) ((x) * (x))
using namespace std;
int main()
{
double no = 4.0;
double result = QUADRAT(++no);
cout << result;
return 0;
}
Thanks alot :>
The preprocessor will replace
QUADRAT(++no)with((++no) * (++no))in that example.That would increment
notwice, if it weren’t for the fact that there are no sequence points between the two increments, so you are actually causing undefined behaviour. Any output you see is valid because no one can tell what will happen.