声明中的“declarator = initializer”是赋值表达式吗?

Is `declarator = initializer` in a declaration an assignment expression?

在 C11 标准中

6.5.16 Assignment operators Syntax

assignment-expression:
conditional-expression
unary-expression  assignment-operator  assignment-expression

assignment-operator: one of = *= /= %= += -= <<=  >>=  &=  ^=  |=

6.7 Declarations

Syntax

declaration:
declaration-specifiers init-declarator-listopt ;
static_assert-declaration
declaration-specifiers:
storage-class-specifier  declaration-specifiersopt
type-specifier  declaration-specifiersopt
type-qualifier  declaration-specifiersopt
function-specifier  declaration-specifiersopt
alignment-specifier  declaration-specifiersopt
init-declarator-list:
init-declarator
init-declarator-list , init-declarator
init-declarator:
declarator
declarator = initializer

declarator = initializer中的=是赋值运算符吗?

声明中的declarator = initializer是赋值表达式吗?

我的问题来自

谢谢。

本例中的 = 字符 不是 赋值运算符,而是声明语法的一部分。

这类似于 , 可以用作逗号运算符、函数参数的分隔符或声明的分隔符。在这两种情况下,语言都可以从周围的上下文中知道它的使用方式。

关于语法 declarator = initializer,它不是赋值表达式,但是 initializer 是。从 6.7.9p1:

initializer:
  assignment-expression
  {initializer-list}
  {initializer-list,}

这意味着你可以这样做:

int x;
int y = x = 3;   // the second = is an assignment operator, the first one is not