Search code examples
csyntaxdeclarationidentifier

Is an expression including array subscripting can be an identifier?


int a[2][4] = {........};

In the code above, a is an identifier of array type. But I'm curious whether a[2], which is an array of 4 int elements, is also an identifier?


Solution

  • a[2] is not an identifier.

    The definition of identifiers in N1570 6.4.2 is

    identifier:
        identifier-nondigit
        identifier identifier-nondigit
        identifier digit
    
    identifier-nondigit:
        nondigit
        universal-character-name
        other implementation-defined characters
    
    nondigit: one of
        _ a b c d e f g h i j k l m
          n o p q r s t u v w x y z
          A B C D E F G H I J K L M
          N O P Q R S T U V W X Y Z
    
    digit: one of
        0 1 2 3 4 5 6 7 8 9
    

    I don't think [ and ] are included in the "implementation-defined characters" for typical C compilers because they are used as array subscripting operator (N1570 6.5.2.1)