# Thread: pointer question.... pointer theory?

1. ## pointer question.... pointer theory?

Ok, I am kind of confused here with pointers and arrays, I was wondering if someone could explain this to me:

char (*a)[5] - "a" is a pointer to an array of 5 characters

char *a[5] - "a" is an array of pointers to characters

actually, the 2nd one makes sense to me, because char* is the data type and we have created the a[5] array of this data type

but the 1st line I do not understand.... what is the name of this array of 5 characters? Why does a point to it? what do the paranthese do?

I appreciate any help with this, it's confusing to me. Thank you

2. what is the name of this array of 5 characters?
There is no name since the array doesn't exist. In this case 'a' is just a variable which can be assigned to the address of an array pointer. Proper usage of 'a might look like:

Code:
```char (*a)[5];
char b[5];
a = &b;
*a[0] = 'a';```
If you tried to assign an index value to the array 'a' points to without assigning it to an array first, you will get an error.

The parenthesis are just used to distinguish the declaration from the second example you have listed there. It is similar as to when you declare a function pointer.

3. so my pointer needs to be derefrenced twice? AS in this code:

Code:
```#include <stdio.h>

main()
{
char (*a)[5];
char *h;
char abc[5] = "abcd";

a = abc;

printf("%c\n",a[0][2]);

getchar();
}```

4. no, more like this:
Code:
```int main(void)
{
char (*a)[5];
char *h;
char abc[5] = "abcd";

a = &abc;

printf("%c\n",(*a)[2]);
// or
printf("%c\n",*((*a) + 2));

return 0;
}```

5. I think that when you put
Code:
`a = &abc;`
it should've been:
Code:
`a = abc;`
since abc is an array with 5 elements and therefore abc is the pointer constant to the first element in the array.

Right?

6. no. When I put
Code:
`a = &abc;`
I meant to put
Code:
`a = &abc;`
'a' doesn't point to an array. It points to a pointer which points to an array.