#include <iostream>
using namespace std;
#define MULTIPLY(a, b) a*b
int main(){
cout << MULTIPLY(2+3, 3+6);
return 0;
}
I expected this to print 40
since five times eight is forty. Why does it print 17
?
#include <iostream>
using namespace std;
#define MULTIPLY(a, b) a*b
int main(){
cout << MULTIPLY(2+3, 3+6);
return 0;
}
I expected this to print 40
since five times eight is forty. Why does it print 17
?
因为C ++宏不是函数。它们是文本副本,因此意味着:
cout << 2 + 3 * 3 + 5;
那是2 +(3 * 3)+ 5