<>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.

©2020 ioDraw All rights reserved
Centralized processing (mean centering) The myth and truth of C Notes on language learning —— Pointer : Pointer and one dimensional array java properties Profile tool class Detailed explanation PHP Medium die,exit,returnC++ String And char* Mutual conversion 《 From machine learning to deep learning 》 note (2) Unsupervised learning python Medium gc Recovery mechanism PHP call shell command Mediating effect , What about regulatory effect and interaction ?Python Student information management system ( Lite )