ByteSurfer said:
some times is am kinda confused.
they like to code
is that both are of the same ??
Yes, it doesn't matter if you have white space before or after the '*'.
There's also the third and fourth possibility:
char * a;
char*a;
That shows it doesn't matter at all where and how much white space
you put before ot after the asterisk.
Some people prefer 'char*' to 'char *' because they feel that it
makes it more obvious that the variable to be defined is a pointer,
while others don't like it because they feel that it makes it easier
to overlook that in
char* a, b;
'b' isn't a pointer but a simple char variable despite the '*' after
the 'char'.
*const char a;
-> a pointer of a constant address to a character
No, that's a syntax error. You can't have a '*' at the start when
defining a variable.
const char* a; or const char *a;
-> a constant value of a char.
No, that's a pointer to an array of chars with the attached promise
that you won't change the contents of what the pointer points to.
This is quite useful when you use pointers that point to literal
strings, i.e.
const char *my_hello = "Hello, boys and girls!";
because the compiler may be able to gently remind you you're doing
something stupid when you don't keep your promise, or when you use
this for function arguments to indicate that the function is not
going to change the elements of the array it receives. An example is
char *strcpy( char *dest, const char *src );
This makes it immediately clear that strcpy() will only change the
destination string, but will leave the source string alone. And
again it doesn't matter if you have white space before or after
the '*' or before and after the asterisk or none at all.
then how bout *const char* a;
will the spaces char* and char * the same ??
That's also a syntax error.
Regards, Jens