Pointers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson


What is the difference between the two codes: Char *trip[]= {"ham", "BUM", "Tum", }; Char trip[][]= {"ham", "BUM", "Tum", }; Thank you for the answers

6th Nov 2018, 6:59 AM
1 Answer
+ 8
The correct code would be this: int main() { char *trip[]= {"ham", "BUM", "Tum", }; char trop[][4]= {"ham", "BUM", "Tum", }; So the first array (trip) contains elements of whatever the length you want but the second array (trop) is a multidimensional array that takes as elements other arrays (in this case strings) that have a maximum length of 4 elements (because I wrote 4 but you can change that value). So at the end, this two printf statements will give the same output: printf("%s \n",trip[1]); printf("%s",trop[1]); //output: BUM
6th Nov 2018, 8:59 AM
Uni - avatar