Re: off topic question



"Rich Gautier" <rgautier cox net> writes:

However, I have a follow-on question - isn't it the pointer itself that is
declared constant, not the character array that it points to?

No, C declarations should be read "inside out", so 

        const char *s;

should be read as "s is a pointer to (const char)", ie., s points to
characters you can't change.

The declaration

        char *const s;

means "s is a constant pointer to characters", ie., you can't change
where s points, but you can change the characters it points to.

The program cdecl is helpful:

        horse09:~% cdecl
        Type `help' or `?' for help
        cdecl>
        cdecl> explain const char *s;
        declare s as pointer to const char
        cdecl> 
        cdecl> explain char *const s;
        declare s as const pointer to char
        cdecl> 
        cdecl> explain const char *const s;
        declare s as const pointer to const char
        cdecl> 
        cdecl> declare s as const pointer to char
        char * const s
        cdecl> 



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