What is the difference between char *a and char a[]?

What is the difference between char *a and char a[]?

Using char*a there is no problem to edit local data.Example: Array is a local data.
Where as char a[] is a local pointer to global, static(constt) data.You can not modify the constt data.

char *s = "vivek";
+-----+        +---+---+---+---+---+---+------+
| s: | *======> | v | i | v | e | k |'\0'|
+-----+        +---+---+---+---+---+---+------+
Pointer              Anonymous array

char s[] = "vivek";
+----+----+----+----+-----+------+
s: | v | i | v | e | k |'\0' |
+----+----+----+----+-----+------+
s[0] s[1] s[2] s[3] s[4] s[5] 




By:Vivek Kr. Agarwal
Date:2006-01-09 00:00:00

char a[]; is an variable of array store elements of same data type.
from above the array a[] store only characters can't store integers values.
char *a; is an pointer that stores address of the variable. since pointer *a is a variable it also have an address. 

By:Jayavardhan.S
Date:2001-03-11 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher