++*(p++)
- This is equivalent to ++*p;p++;
So here first byte value (character) of address stored in variable p
is going to increment by 1
. And then value of variable p
is going to increment, that means p is going to point (store) address of 2nd character of string literal ("abcd"
).
Now go through the below two variable declaration.
char *p = "abcdef";
char p1[] = "abcdef"
Here for first variable p
, 4 bytes will be allocated in stack to
store the address of the string literal "abcdef"
and then 6 byte will
be allocated to store the string literal ("abcdef"
) in text segement of process memory. Always text segment is read only. So this value cannot be modifed.
Then for second variable 6 byte will be allocated in stack itself to
store the string ("abcdef"
). Stack segment in process memory has both
read and write access.
So performing ++*p
(modifying value in address) is applicable for variable p1
but not appilcable for variable p
.