Strings

suggest change

Introduction

C has no string type. A string is a convention: a contiguous sequence of characters terminated by a null character, '\0'.

The string "abc" therefore occupies four characters: 'a', 'b', 'c', and '\0'.

See String literals for the literal itself, including encoding prefixes and the rule that modifying a literal is undefined behavior.

Syntax

char str1[] = "Hello, world!";  /* Modifiable array, sized by the initializer. */
char str2[14] = "Hello, world!"; /* Modifiable array. 14 includes the null character. */
char *str3 = "Hello, world!";   /* Points at a literal. Writing through str3 is undefined behavior. */

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents