0
Can you help me to solve this in C ?
Given the following statements: char *name[] = {”Ali”,”Ani”,”Tono”}; char name[][10] = {”Ali”,”Ani”,”Tono”}; Compare and contrast the two name identifiers above !
1 ответ
+ 1
Not a C expert here, but going to try to help you out.
First, they aren't the same array
char *name[] is the same as char name[][]
But more importantely, the main difference is that char *name[] is going to allocate an array of pointer
So during runtime you will be able to do
char *name[] = {"Alice", "Bar"};
char *foo = "TEST";
name[1] = foo;
and this
char name[][10]= {"Alice", "Baz"};
char foo[] = "TEST2";
name[1] = foo;
but you should never do
name[1][1] = 'u';
if you're using pointers
but you can do it if you're using arrays.
Thisis a great SO post: https://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s
Hope I didn't say mistakes and hope I help you.