Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The const keyword is not included in these declarationsthis declaration.

Code Block
bgColor#FFcccc
char* c1c = "Hello"; // Bad: assigned to non-const
char c2[] = "Hello"; // Bad: assigned to non-const
char c3[6] = "Hello"; // Bad: assigned to non-const
c1[c[3] = 'a'; // Undefined (but compiles)

...

Code Block
bgColor#ccccFF
char* const c1c = "Hello"; // Good
//c[3] = 'a'; would cause a compile error

Aside

Note that the following code is acceptable, as a and b do not actually point to string literals. They are char array objects which have had characters copied into them, and therefore are modifiable.

Code Block
char const c2a[] = "Helloabc"; // Good
char const c3b[63] = "Helloabc"; // Good
//c1[3

The above code is equivalent to:

Code Block

char a[] = {'a', 'b', 'c', '\0'};
char wouldb[] cause= {'a compile error', 'b', 'c'};

Non-Compliant Coding Example 2.a

...