定义宏定义时出错

use*_*497 2 c++

当我使用#define功能时,我发现了一些奇怪的东西.在下面的代码中,如果我从输入得到i值得到输出为.但是,如果我通过评论10,12和13行声明,那么我的输出是.谁能解释我这是怎么回事?提前致谢'10'i132i=10144

#include <iostream>
using namespace std;

#define Double(X) X*X 

int main()
{

 //int i=10;
 int i;

cout<<"Enter the i values:" <<endl;
cin>>i;

cout<<"Values is:"<<Double(++i)<<endl;

 return 0;
}
Run Code Online (Sandbox Code Playgroud)

Gri*_*han 6

Double(++i) will expand to ++i * ++i. In this expression, i is modified twice without an intervening sequence point, which is undefined behavior.

Read: So, what's wrong with using macros?