Re: Pointers
Jens.Toerring_at_physik.fu-berlin.de
Date: 03/08/05
- Next message: schears_at_hotpop.com: ""Out of Memory" error during Borland C++ 5.02 compile"
- Previous message: Flash Gordon: "Re: regcmp warning: improper pointer/integer combination: op "=""
- In reply to: ByteSurfer: "Re: Pointers"
- Next in thread: Randy Yates: "Re: Pointers"
- Reply: Randy Yates: "Re: Pointers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 8 Mar 2005 16:02:51 GMT
ByteSurfer <bytesurfer@gmail.com> wrote:
> some times is am kinda confused.
> they like to code
> char* a;
> char *a;
> 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'.
> and some more is it :
> *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
-- \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de \__________________________ http://www.toerring.de
- Next message: schears_at_hotpop.com: ""Out of Memory" error during Borland C++ 5.02 compile"
- Previous message: Flash Gordon: "Re: regcmp warning: improper pointer/integer combination: op "=""
- In reply to: ByteSurfer: "Re: Pointers"
- Next in thread: Randy Yates: "Re: Pointers"
- Reply: Randy Yates: "Re: Pointers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|