jeniffer said:
char *a="this is a string";
char a[]="this is a string";
first is a pointer while second is an array.Tell me more differences
I'm going to rewrite this a little:
char *ptr="this is a string";
char arr[]="this is a string";
In the above code, we're talking about 3 distinct objects: the string
literal "this is a string", the pointer ptr, and the array arr. The
following hypothetical memory map shows the state of each object after
initialization (best viewed with a fixed-size font):
Item Address Contents
---- ------- --------
literal 0x0800 "this is a string"
ptr 0x1000 0x0800
arr 0x2000 "this is a string"
The string literal has its own address in memory, and may not be
writable (i.e., you may not be allowed to write to the bytes between
0x0800 and 0x0811; assume that you can't).
The pointer ptr contains the address of the string literal. Since the
literal may not be writable, you may not write to *ptr or ptr[n];
however, you can assign a new value to ptr (i.e., ptr=NULL,
ptr=&arr[0], ptr=malloc(16), etc.), and if this new value points to
writable memory, you may then also write to *ptr or ptr[n].
The array arr contains a *copy* of the contents of the string literal.
The array contents are writable, so you can write to *arr or arr[n];
however, the array object itself is not writable, so you may not write
arr=NULL, or arr="this is a string", or arr=p, etc.