If I want to print out array of string like:
char juices_A[][12] = { "dragonfruit", "waterberry", "sharonfruit", };
I can simply use juices_A[0]
,juices_A[1]
,juices_A[3]
, respectively as a pointer to string "dragonfruit"
, "waterberry"
, "sharonfruit"
, and print them out.
But what if I want to print out array of int array like:
int data[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
I can not simply use data[0]
,data[1]
,data[2]
as pointer to { 1, 2, 3 }
, { 4, 5, 6 }
, { 7, 8, 9 }
, I need to adopt a more complicated way to print them out. I need to use loop inside loop. So I want to know why I can not use pointer in the int situation? I read on book "Array variables are like pointers.." so I assume int array variable data[0],data[1],data[2]
are also like pointers...
#include <stdio.h>
int main() {
int i_A = 0;
char juices_A[][12] = { "dragonfruit", "waterberry", "sharonfruit", };
for (; i_A < 3; i_A++)
printf("%s;", juices_A[i_A]);
puts("");
int i_B = 0;
int data[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
for (; i_B < 3; i_B++) {
int i_C = 0;
for (; i_C < 3; i_C++)
printf("%i,", data[i_B][i_C]);
printf(";");
}
return 0;
}
the result is:
dragonfruit;waterberry;sharonfruit;
1,2,3,;4,5,6,;7,8,9,;