Print address of character array

Please tell me how char*arr[4], char *(*ptr)[4]=&arrand (*ptr)[i]mean here step by step.

#include<stdio.h>
int main()
{
int i;
char *arr[4]={"c","c++","java","vba"};
char *(*ptr)[4]=&arr;
for(i=0;i<4;i++)
       printf("address of string %d : %u\n",i+1,(*ptr)[i]);
return 0;
}

output:
address of string 1 : 178
address of string 2 : 180
address of string 3 : 184
address of string 4 : 189

and if I change the printf statement:

printf("string %d : %s\n",i+1,(*ptr)[i]);

output:
string 1 = c
string 2 = c++
string 3 = java
string 4 = vba

also give me some links where I can find similar questions for practice.

+4
source share
3 answers

char *arr[4]- an array of 4 pointers to char. In other words, it is an array of 4 lines. char *(*ptr)[4]=&arrdeclares a pointer to an array of 4 pointers to char. The assignment on this line assigns the address of the first element of the array arr; *(ptr)[i]casts the ith element of the array ptr.

C-. .

0

undefined. ?

, undefined.
*(ptr)[i] char *. %u .
%p .

 printf("address of string %d : %p\n",i+1,(void *)*(ptr)[i]);
-1

it

*(ptr)[i]

it should be

(*ptr)[i]

And: Use %pto print pointers void *, so the print line should look like this:

printf("address of string %d : %p\n", i+1, (void *)(*ptr)[i]);
-1
source

All Articles