Re: const modifier

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tune more wrote:
> Thanks Joe, so in first one, value is constant but
> address still can be changed. In second, both value
> and address can not be changed.

Read it again. In the second case, the value pointed
to *can* be changed, but the pointer itself cannot.

> (chaning addresses
> might not make sense,

Sure it does. You often want to change the value of
a pointer (an address) to point at a different
memory location. That's pretty much the whole
reason to have pointer variables and address
arithmetic.

Cheers,

-- Joe

> but technically it still can be
> changed.) Right?
> 
> --- Joseph A Knapka <jknapka@earthlink.net> wrote:
> 
>>Joseph A Knapka wrote:
>>
>>>tune more wrote:
>>>
>>>
>>>>Hi,
>>>>
>>>>Here is an example of "const modifier" usage:
>>>>     int execv(const char *path, char *const
>>>
>>argv[]);
>>
>>>>Is there any different between const before char
>>>
>>* and
>>
>>>>const after char *.
>>>>
>>>
>>>const char* pc1; /* A pointer to constant
>>
>>characters: *pc1 = 'a'
>>
>>>                    will fail to compile, but
>>
>>pc1="a" is OK. */
>>
>>>char * pc2 const; /* A constant pointer to
>>
>>non-const character.
>>
>>>                    *pc2='a' is OK, but pc2="a"
>>
>>will fail
>>
>>>                    to compile. */
>>
>>Sorry, that second decl should be
>>
>>char * const pc2; /* A const * to non-const char */
>>
>>
>>>You need to find a copy of a recent edition of K&R
>>
>>(that
>>
>>>is, Kernighan & Ritchie, "The C Programming
>>
>>Language").
>>
>>...and apparently I need to re-read mine...
>>
>>Cheers,
>>
>>-- Joe
>>
>>
>>
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Y! Web Hosting - Let the expert host your web site
> http://webhosting.yahoo.com/
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
> 



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux