this statement says a pointer v[i] is assigned to an address
You seem to be confusing an array of characters with an array of character pointers: v[i] is simply the i-th member of an array consisting of char *.
In C everything is passed by value, so are the pointers. You are right in assuming that v[] is an array storing char pointers.
The code is valid because the pointers are being swapped, not the char variables pointed at: v[i] and v[j] are pointers, therefore temp should be a pointer as well.
The following test code demonstrates it from the caller's point of view: you can easily observe what is happening in your function. Pointers are being passed as values which are getting swapped, but the char variables that they point at are left as they are (b and c in this example).
#include <stdio.h>
void swap2(char *v[], int i, int j) {
char *temp;
temp = v[i];
v[i] = v[j];
v[j] = temp;
}
int main (void)
{
char a = '1', b = '2', c = '3', d = '4', e = '5';
char *v[5] = {&a, &b, &c, &d, &e};
for(int i = 0; i < 5; i++)
printf("%p:%c ", (void*)(v[i]), *(v[i]));
printf ("\n");
swap2(v, 1, 2);
for(int i = 0; i < 5; i++)
printf("%p:%c ", (void*)(v[i]), *(v[i]));
printf ("\n");
printf("b = %c\n", b);
printf("c = %c\n", c);
return 0;
}
tempacharinstead ofchar *, you'd be assigning achar *to achar, and you'd probably get a compilation error...