GOEDUHUB Online Courses || Last Batch Student's Projects || COVID-19 Projects(AI-ML) || Universities  ||  Placement Preparation  
+91-7976731765 Free Online Tutorials ||  MACHINE LEARNING || Python || DBMS || OOPs || DSA || Java || Linux/Unix ||  C Programming
0 like 0 dislike
in Tutorial & Interview questions by Goeduhub's Expert (8k points)

An array of strings can mean a couple of things:

1 Answer

0 like 0 dislike
by Goeduhub's Expert (8k points)
Best answer

An array of strings can mean a couple of things:

  1. An array whose elements are char *s
  2. An array whose elements are arrays of chars

We can create an array of character pointers like so:

char * string_array[] = {    "foo",    "bar",    "baz" };

Remember: when we assign string literals to char *, the strings themselves are allocated in read-only memory. However, the array string_array is allocated in read/write memory. This means that we can modify the pointers in the array, but we cannot modify the strings they point to.

In C, the parameter to main argv (the array of command-line arguments passed when the program was run) is an array of char *: char * argv[].

We can also create arrays of character arrays. Since strings are arrays of characters, an array of strings is simply an array whose elements are arrays of characters:

char modifiable_string_array_literals[][4] = {    "foo",    "bar",    "baz" };

This is equivalent to:

char modifiable_string_array[][4] = {    {'f', 'o', 'o', '\0'},    {'b', 'a', 'r', '\0'},    {'b', 'a', 'z', '\0'} };

Note that we specify 4 as the size of the second dimension of the array; each of the strings in our array is actually 4 bytes since we must include the null-terminating character. 

 Placements:   List of companies | Logical Reasoning Questions | Quantitative Aptitude Questions | General English Questions | Technical-MCQ and Interview Questions
 Important Lists: List of NITsList of IITsList of Exams After Graduation | List of Engineering Entrance Examinations (UG/PG)College ReviewsCollege Fest, Events & WorkshopsKnowledge ShareTrainees/Interns After 15-04-2020
Exams & Cutoffs: JEE Main | JEE Advanced | GATE | IES | ISROList of PSUs || Cutoff-GATECutoff_IIT-JEECS-ScopeECE ScopeEE-Scope
 Download Previous Year Papers For:  GATE | IES | RAJASTHAN TECHNICAL UNIVERSITY (RTU-Kota)RPSC Technical Exams | ISRO
About Us | Contact Us   Social::   |  |