Re: what's the use of "const char*" as a parameter?
Victor Bazarov wrote:
Virtual_X wrote:
>some function make the data type of it's parameters as "const char*"
>>
>why not use char or char* instead
>what would be different
>
The type 'char' can only help passing a _single_ character.
>
The type 'char*' can help passing an array of non-constant characters.
>
The type 'const char*' helps passing an array of constant characters.
>
It means the function needs an array (often it's a C-string),
Even though it usually does need one for the case of pointers to char, the
declaration doesn't mean that. The function gets a pointer to a single
char. It's just a convention between the function and the caller that this
actually points to the first element of an array.
Re: what's the use of "const char*" as a parameter?
A function which parameter is const char *, it can accept char * and
const char * type of argument.
But if function's parameter is only char *, it will give a compilation
error when you try to
pass a const char *.
On Jul 12, 11:30 pm, Rolf Magnus <ramag...@t-online.dewrote:
Victor Bazarov wrote:
Virtual_X wrote:
some function make the data type of it's parameters as "const char*"
>
why not use char or char* instead
what would be different
>
The type 'char' can only help passing a _single_ character.
>
The type 'char*' can help passing an array of non-constant characters.
>
The type 'const char*' helps passing an array of constant characters.
>
It means the function needs an array (often it's a C-string),
>
Even though it usually does need one for the case of pointers to char, the
declaration doesn't mean that. The function gets a pointer to a single
char. It's just a convention between the function and the caller that this
actually points to the first element of an array.
A function which parameter is const char *, it can accept char * and
const char * type of argument.
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.c om/c++-faq-lite/how-to-post.html>
Comment