<分区>
如果我这样初始化变量:
static int i = 2 * 2 / 0;
然后,编译器给我一个错误。
prog.c: In function 'main':
prog.c:5:23: warning: division by zero [-Wdiv-by-zero]
static int i = 2 * 2 / 0;
^
prog.c:5:17: error: initializer element is not constant
static int i = 2 * 2 / 0;
但是,如果我使用 ||
而不是 *
,就像这样:
static int i = 2 || 2 / 0;
那么就编译成功了。
根据 Operator Precedence , *
的优先级高于 ||
。因此,首先对 2/0
操作求值。我说得对吗?
那么,为什么 static int i = 2 || 2/0;
报错?