CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

Initializing character arrays

As we've just seen with 1-dimensional arrays of integers, C also provides facility to initialize character arrays.

All of the following examples are valid:


char greeting[5] = { 'h', 'e', 'l', 'l', 'o' };

char today[6]    = "Monday";

char month[]     = "August";

The 3rd of these is the most interesting.
We have not specified the size of the array month ourselves, but have permitted the compiler to count and allocate the required size.

 


CITS2002 Systems Programming, Lecture 5, p6, 5th August 2024.