Why declare pointer to array if arrays are already pointers?

4

If a char array is already a pointer, why declare a pointer to the array?

And what's the difference between char exemplo[10] and char *exemplo[10] ?

    
asked by anonymous 08.10.2015 / 03:19

2 answers

6

A char array (or other type) is NOT a pointer.

An array is an array; a pointer is a pointer (see c-faq section 6 ).

When an array is used as a value, it is converted to a pointer to its first element.

The difference between char exemplo[10] and char *exemplo[10] is that the first one declares an array of 10 characters and the second declares an array of 10 pointers.

    
08.10.2015 / 10:31
5

You are not declaring a pointer to array . You are declaring a pointer to char . They are different things .

In the first example, you have an array with 10 char s. In the second it has an array with 10 pointer to char .

The pointer to char is almost synonymous with string . The C language does not have string , but this is closest to one.

Obviously the pointer needs to point to an area of memory that has a sequence of char s.

    
08.10.2015 / 03:32