...
In the following noncompliant code, the const keyword has been omitted.:
| Code Block | ||||
|---|---|---|---|---|
| ||||
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 | ||||
|---|---|---|---|---|
| ||||
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 | ||||
|---|---|---|---|---|
| ||||
char c[] = "Hello"; |
...
In the following noncompliant code, the const keyword has been omitted.:
| Code Block | ||||
|---|---|---|---|---|
| ||||
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 | ||||
|---|---|---|---|---|
| ||||
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 | ||||
|---|---|---|---|---|
| ||||
wchar_t c[] = L"Hello"; |
...