MD XF MD XF - 8 months ago 61
C Question

C Programming terminology

Take this declaration:

int i = 80;

This is my understanding of the terms used to describe each part (correct me if I'm wrong):

  • int
    is the variable type

  • i
    is the declarator

  • =
    is the assignment operand

What term is used to describe the

Another example:

char *c = "a";
// char - variable type
// c - declarator
// = - assignment operand
// "a" - ?

Answer Source

For the proper names of each part of the C syntax, you should go to the C standard and read the language grammar. The relevant (incomplete) pieces are:

    declaration-specifiers init-declarator-list opt ;

    storage-class-specifier declaration-specifiers opt
    type-specifier declaration-specifiers opt
    type-qualifier declaration-specifiers opt
    function-specifier declaration-specifiers opt
    alignment-specifier declaration-specifiers opt

    init-declarator-list , init-declarator

    declarator = initializer

So for example:

  • static int x = 80, y = 90; is a declaration.
  • static is the declaration specifier.
  • int is a type specifier that works as a declaration specifier.
  • x (and y) is an identifier (grammar is elsewhere) that works as a declarator.
  • = is a token that separates the declarator from the initializer. In this context it is not an operator.
  • 80 (and 90) is an expression that works as an initializer.
  • , is a token (not an operator) that separates one declarator plus initialization from the next one.
  • ; is a token that marks the end of the declaration.