| Equal sign ('=')

Previous | Punctuators | Next

The `'='` (equal sign) used as a punctuator separates variable declarations from initialization lists. For example,

    int array[5] = { 1, 2, 3, 4, 5 };
    char *name = "Fred";
    int x = 12;

In a C function, no code can precede any variable declarations. Note that the GNU C, in opposite to other C dialects, allow non-constant initializers (like in C++).
The equal sign is also used in enumerations:

    enum colors {Blue = 1, Red = 2, Green = 4, Light = 8};

It is also used as the assignment operator in expressions:

    a = b + c;

or even:

    a = b + 2 * (c = d - 1);

Note: The GNU C extends the usage of equal sign (as a punctuator) to allow labeling elements in initializers.