Pointers | Sololearn: Learn to code for FREE!

0

Pointers

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

11/6/2018 6:59:35 AM

Kosai

1 Answer

New 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