Monday, January 6, 2025
HomeComputer ScienceArray of Strings in C

Array of Strings in C

In C, an array of strings is essentially an array of character pointers (char *) where each element of the array points to a string (which is an array of characters terminated by a null character '\0'). Strings in C are handled as arrays of characters, so an array of strings is an array where each element holds a pointer to a character array.

See also  Micros and its Types in C

Declaration and Initialization

To declare an array of strings, we can use the following syntax:

char *arr[] = { "Hello", "World", "C", "Programming" };

This declares an array of pointers to char, where each pointer in the array points to a string literal.

See also  How much does a Computer Science degree cost?

Here’s a breakdown of the components:

  • char *arr[] — an array of char *, meaning an array where each element is a pointer to a character (i.e., a string).
  • { "Hello", "World", "C", "Programming" } — the strings that the array of pointers will point to. Each string is a string literal (automatically null-terminated).
Previous article
Next article
RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Who is iCarly?

Who is Bre Tiesi?

Celebrities Born in 1983

Who is Chris Olsen?

Recent Comments

0
Would love your thoughts, please comment.x
()
x