请问这个输出未定义是什么意思?
std::cout << square(++q) << ' ' << q << std::endl; //输出未定义,++q被执行了两次 结果为9 3;
#include <iostream>
#define sum(x, y) (x) + (y) //#define 本质上是文本替换 如下第五行中2 * sum(3, 5) 运行后为2 * 3 + 5 = 11;
#define square(x) ((x) * (x))
int main() {
std::cout << sum(1, 2) << std::endl << 2 * sum(3, 5) << std::endl;
int q = 1;
std::cout << square(++q) << ' ' << q << std::endl; //输出未定义,++q被执行了两次 结果为9 3;
std::cout << std::endl;
std::cout << std::endl;
int i = 1, a = 0, b = 0;
a = i++; //先赋值后自增 a = i, i = i + 1;
b = ++i; //先自增后赋值 i = i + 1, b = i;
printf("i = %d, a = %d, b = %d",i,a,b);
return 0; //结果:i = 3, a = 1, b = 3
}