Character String Arrays and Initialization

When you define a character string array, you must let the compiler know how much space is needed. One way to do this is to initialize the array with a string constant. With older C implementations, you must use static or external arrays for this purpose, but we'll assume you're using ANSI C and can initialize arrays of any storage class. The following declaration initializes the external array m1 to the characters of the indicated string:

char m1[] = "Just limit yourself to one line's worth.";

This form of initialization is short for the standard array initialization form:

 char m1[] = { `J', `u', `s', `t', ` `, `l', `i', `m', `i', `t', ` `, `y', `o', `u', `r', `s', `e', `l', `f', ` `, `t', ...

Get C Primer Plus®, Third Edition 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.