Re: Doubt about array's name
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 30 Apr 2008 09:28:26 -0700
nembo kid <user@xxxxxxxxxxxxx> writes:
Richard Heathfield ha scritto:
Why not? It's only a copy, after all. It doesn't affect the original
array address in any way whatsoever.
Ok my doubts cleared all.
But anyway I dont'understand because someone add the qualificator
"const" to string array passed to the function (so to avoid any change
of this pointer).
/* Code */
void chartobyte (const char *s)
/* Code */
``const char *s'' declares s as a pointer to const char, not as a
const pointer to char. In other words, you're permitted to modify the
pointer (since it's just a local copy), but you're not permitted to
modify what it points to.
If you wanted to declare a const pointer to char (so the pointer
itself is read-only), you could write:
char *const s;
But function parameters, since they're purely local to the function,
are not typically declared as "const", since any modification won't
affect the caller anyway. You could declare a parameter as "const" if
you don't intend to modify it within the function.
--
Keith Thompson (The_Other_Keith) <kst-u@xxxxxxx>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- References:
- Doubt about array's name
- From: nembo kid
- Re: Doubt about array's name
- From: Richard Heathfield
- Re: Doubt about array's name
- From: nembo kid
- Doubt about array's name
- Prev by Date: Siebel Automation Test Engineer
- Next by Date: Re: Doubt about array's name
- Previous by thread: Re: Doubt about array's name
- Next by thread: Re: Doubt about array's name
- Index(es):
Relevant Pages
|