H Vlems wrote:
> On 10 mrt, 07:20, pavunkumar <pavun....@gmail.com> wrote:
>> Dear Friend
>>
>> Please Explain about this things
>> I have character pointer variable
>>
>> char *p="string";
>> char *s ="string";
>>
>> If I print the both variable of the address
>> It is print same address why ?
>
> The text "string" is a literal (composed of characters though that is
> not important).
> The compiler stores literals in a read-only part of the codefile.
Not necessarily. It's not uncommon for string literals to be writable.
The standard deliberately leaves it unspecified whether or not string
literals can be written to, because there's a fair number of real-world
implementations which do it either way.
Portable code should assume that they are not writable, but not all code
needs to be portable.
> Because it is
> read-only the compiler will store the value only once and refer other
> occurances to the same address.
Again, the standard permits them to be the same; it doesn't require it,
and many compilers don't bother merging them.
|