CHAPTER 7

image

String

A string consists of an array of characters and is delimited by double quotes. There is no string type for storing strings in C. Instead, strings are commonly assigned to a character array as shown here.

char myString[] = "Hi";

Strings in C are terminated with a null character \0, which is used to know where the string ends. The null character is added automatically by the compiler for quoted strings, as in the previous example. The same statement can also be written using regular array initialization syntax, in which case the null character needs to be explicitly included.

char myString[3] = { 'H', 'i', '\0' };

Both statements ...

Get C Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.