|
|
nembo kid said:
> In the following function, [shouldn't s] be a pointer costant (array's
> name)?
It's just a copy. C is pass-by-value. When the argument expression is
evaluated (in the *call* to chartobyte()), the array name is treated as if
it were a pointer to the first element in the array, and this pointer
value is copied into the parameter object that the implementation
constructs for the call.
> So why it is legal its increment?
Why not? It's only a copy, after all. It doesn't affect the original array
address in any way whatsoever.
> /* Code starts here */
> void chartobyte (char *s) {
>
> while (s!=0) {
> printf ("%d", *s);
> s++;
> }
> /* Code ends here */
I think you meant to write:
void chartobyte(const char *s) /* significant difference #1 */
{
while(*s != '\0') /* significant difference #2 */
{
printf("%d", *s);
s++;
}
}
--
Richard Heathfield <http://www.cpax.org.uk>
Email: - www">http://www. +rjh@
Google users: < www.cpax.org.uk/prg/writings/googly.php">http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
|
|