Re: What does const char *s mean? is s a constant or *s?
From: Karthik Kumar (kaykaylance_nospamplz_at_yahoo.com)
Date: 01/24/05
- Next message: sushant: "Re: Why the Range of Int is less by one at positive side?........."
- Previous message: Karthik Kumar: "Re: Finding the time taken by a function"
- In reply to: G Patel: "What does const char *s mean? is s a constant or *s?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 24 Jan 2005 02:17:33 -0800
G Patel wrote:
> I've been looking at some code for string functions (certain
> implementation of them) and the non modified string is usually declared
> as a const char *s in the parameter list.
>
> I was wondering, what exactly does that mean. Does that mean the
> function is restricted from changing the address (changing s) or
> changing what's being pointed to (*s)?
>
If you are working on a *nix-based machine, check if you
have access to the 'cdecl' utility. That should help to
understand these things better.
$ cdecl
Type `help' or `?' for help
cdecl> explain const char * s
declare s as pointer to const char
cdecl>
As a thumb rule, try to interpret by reading them
from right to left.
For that reason, some people find ,
' char const * s; '
much more readable when compared to
' const char * s; ' ,
but then that could be just a style preference.
-- Karthik.
- Next message: sushant: "Re: Why the Range of Int is less by one at positive side?........."
- Previous message: Karthik Kumar: "Re: Finding the time taken by a function"
- In reply to: G Patel: "What does const char *s mean? is s a constant or *s?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|