<>C++ in define How to use

<>1. The code is as follows
#include<cstdio> #include<iostream> #define max(a,b) ((a)>(b)? (a): (b)) using
namespace std; int main(){ int a = 2; int b = 2; int n = max(a,b); printf("n =
%d\n",n); int m = max((++a),b); printf("a= %d ,b = %d, m = %d",a,b,m); return 0;
}
<>2. results of enforcement

What will be the result of this implementation ? Most people will think that the result is :3 2 3. But the sad thing is , give the result as follows :

<>3. reason

With the doubts above , Let's see define The role of ,define Is a macro definition operation . in other words , For what we define
#define max(a,b) ((a)>(b)? (a): (b))
If we call int m = max((++a),b); Will be replaced with ((++a)>(b)? (++a): (b)). So what you get is added twice a.

Technology