MCS-011 Problem Solving and Programming

First year, Semester 1

Chapters

Newsletter

Array of Strings

An array of strings in C is a table of multiple strings. Declaring it involves adding an additional dimension to specify the number of strings. The syntax is:

char array-name[rows][cols];

Example:

char names[5][10];

Here, names is the array, 5 indicates the number of strings, and 10 specifies the maximum length of each string.


Another Example:

An array of strings can be declared and initialized as follows:

char names[3][10] = {"martin", "phil", "collins"};

This creates a two-dimensional array with 3 strings, each with a maximum length of 10 characters. The representation in memory is:


0123456789
martin\0


phil\0




collins\0


Report an issue

Reporting: Array of Strings (topic)

Related Posts