The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
Array of strings is a array which holds strings instead of characters. Arrays of strings are possible by using two-dimensional array or by using pointers. One cannot have array of strings in one dimensional array.
data_type arrayName [size1][size2] = {string1, string2, ..., stringN};
#include <stdio.h> #include .<string.h> int main() { char arr[3][10] = {"INDIA", "AMERICA", "JAPAN"}; printf("%s \n %s \n %s ", arr[0], arr[1], arr[2]); return 0; }
Here, the first index 3 represents that we are going to store three strings in an array and the second index 10 represents the maximum length of the strings in an array.
Lets code a c program to have a strings in array format by using pointer concept
#include <stdio.h> #include .<string.h> int main() { char *arr[3] ; arr[0] = "INDIA"; arr[1] = "AMERICA"; arr[2] = "JAPAN"; printf("%s \n %s \n %s ", arr[0], arr[1], arr[2]); return 0; }
Here, index 3 represents that we are going to store three strings in an array of length n.
Same thing happens for the strings "AMERICA" and "JAPAN"
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019