Versions Compared

Key

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

...

In the following noncompliant code, the const keyword has been omitted.:

Code Block
bgColor#FFcccc
langc
char *c = "Hello";

...

In this compliant solution, the characters referred to by the pointer c are const-qualified, meaning that any attempt to assign them to different values is an error.:

Code Block
bgColor#ccccFF
langc
const char *c = "Hello";

...

In cases where the string is meant to be modified, use initialization instead of assignment. In this compliant solution, c is a modifiable char array that has been initialized using the contents of the corresponding string literal.:

Code Block
bgColor#ccccFF
langc
char c[] = "Hello";

...

In the following noncompliant code, the const keyword has been omitted.:

Code Block
bgColor#FFcccc
langc
wchar_t *c = L"Hello";

...

In this compliant solution, the characters referred to by the pointer c are const-qualified, meaning that any attempt to assign them to different values is an error.:

Code Block
bgColor#ccccFF
langc
wchar_t const *c = L"Hello";

...

In cases where the string is meant to be modified, use initialization instead of assignment. In this compliant solution, c is a modifiable wchar_t array that has been initialized using the contents of the corresponding string literal.:

Code Block
bgColor#ccccFF
langc
wchar_t c[] = L"Hello";

...