How to edit the index of an array of pointers?

Ok, so I'm wondering how you are going to use an array of pointers to access the value in the index. Such as:

printf("%c", (*character)[0]);

I know that my code is incorrect, but I know how to fix it. Let's say I want to access position 0 in an array of pointers and then print it as shown above, how would I do this?

+4
source share
3 answers

Alleged symbol char character[] = {'1'};

character[someIndex] means someIndex[character] means  *(character+someIndex) 

If this is what you wanted to know. Therefore, you should do something like:

printf("%c", *(character+0));

Which is equivalent

printf("%c", *character);

printf("%c", character[0]);

Just skipped - regarding this statement

index of an array of pointers?

, . .

+3

, -

char *character="something";

.
, , . : -

printf("%c",character[1]);//


printf("%c",*(character+1));


printf("%c",*(1+character));//

,
printf("%c",1[character]);

+1

char * arr [20] = { "Stackoverflow" };

This means that you have an array of char pointers, where 20 memory addresses are stored in an array of size 20. The 1st memory cell in arr [0] points to the string "Stackoverflow", and the rest of them are not assigned (so you get garbage value or possibly a segmentation error). Now, if you want to access the 0th memory cell, just do the following:

E ("% s \ n", arr [0]);

+1
source

All Articles