#include <iostream>
using namespace std;
#define MULTIPLY(a, b) a*b
int main(){
cout << MULTIPLY(2+3, 3+5);
return 0;
}
I expected this to print 40
since five times eight is forty. Why does it print 16
?
#include <iostream>
using namespace std;
#define MULTIPLY(a, b) a*b
int main(){
cout << MULTIPLY(2+3, 3+5);
return 0;
}
I expected this to print 40
since five times eight is forty. Why does it print 16
?
Because C++ macros are not functions. They are text copies, so that means:
cout << 2+3*3+5;
Which is 2 + (3*3) + 5