[dcl.init.string]

# 9 Declarations [[dcl]](./#dcl)

## 9.5 Initializers [[dcl.init]](dcl.init#string)

### 9.5.3 Character arrays [dcl.init.string]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L6051)

An array of ordinary character type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types")),char8_t array,char16_t array,char32_t array,
or wchar_t array
may be initialized by
an ordinary string literal,
UTF-8 string literal,
UTF-16 string literal,
UTF-32 string literal, or
wide string literal,
respectively, or by an appropriately-typed [*string-literal*](lex.string#nt:string-literal "5.13.5 String literals [lex.string]") enclosed in
braces ([[lex.string]](lex.string "5.13.5 String literals"))[.](#1.sentence-1)

Additionally, an array of char orunsigned char may be initialized by
a UTF-8 string literal, or by
such a string literal enclosed in braces[.](#1.sentence-2)

Successive
characters of the
value of the [*string-literal*](lex.string#nt:string-literal "5.13.5 String literals [lex.string]") initialize the elements of the array,
with an integral conversion ([[conv.integral]](conv.integral "7.3.9 Integral conversions"))
if necessary for the source and destination value[.](#1.sentence-3)

[*Example [1](#example-1)*:

char msg[] = "Syntax error on line %s\n"; shows a character array whose members are initialized
with a[*string-literal*](lex.string#nt:string-literal "5.13.5 String literals [lex.string]")[.](#1.sentence-4)

Note that because'\n' is a single character and
because a trailing'\0' is appended,sizeof(msg) is25[.](#1.sentence-5)

â *end example*]

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L6098)

There shall not be more initializers than there are array elements[.](#2.sentence-1)

[*Example [2](#example-2)*:

char cv[4] = "asdf"; // error is ill-formed since there is no space for the implied trailing'\0'[.](#2.sentence-2)

â *end example*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L6108)

If there are fewer initializers than there are array elements, each element not
explicitly initialized shall be zero-initialized ([[dcl.init]](dcl.init "9.5 Initializers"))[.](#3.sentence-1)
