Difference between pointer and array

Possible duplicates:
Difference between char * str = "STRING" and char str [] = "STRING"?
C: differences between pointer and array

Hi,

Can someone tell me the difference between the statements below?

char *p = "This is a test"; char a[] = "This is a test"; 
+7
source share
4 answers

When you declare char p [], you declare an array of characters (which is readable and writable), and this array is initialized with some sequence of characters, i.e. "This is test" is copied to the elements in this array.

When you declare char * p, you declare a pointer that points directly to some constant literal, not a copy. They can only be read.

+7
source

1 - a pointer that points to a read-only section of the program containing the string "This is test \ 0".

2 - memory (13 bytes), which is initialized by the contents mentioned above.

+3
source

a is an array, which means you can use the sizeof() operator on a , and sizeof(a)/sizeof(a[0]) is equal to the length of the array.

p is a pointer to a constant region of memory.

+3
source
0
source

All Articles