[pointers and arrays]: The difference between an array name and a pointer
- From: iamchiaweilin@xxxxxxxxx
- Date: 2 Oct 2006 09:21:12 -0700
Hello all:
What's the difference between p and q in the following statements?
char p[] = "Hello";
char *q = "Hello";
I know q stores the address of 'H'.
Question is: does p store the address of 'H' too?
I know p is the name of the array that contains "Hello". Is array name
a pointer?
In other words, is p exactly the same as &p[0]?
p and q are the same if you want to print them out by %s.
Is there a case where p and q (array name and pointer to the array)
can not be used interchangably? I knew there is, such as sizeof( ).
p.s. I remembered reading somewhere on the Net says that the statement
char *q = "Hello"
is not a good style of programming. coz you do not know whether q
points to a valid address or not.
Is it true?
.
- Follow-Ups:
- Re: [pointers and arrays]: The difference between an array name and a pointer
- From: Keith Thompson
- Re: [pointers and arrays]: The difference between an array name and a pointer
- From: Richard Heathfield
- Re: [pointers and arrays]: The difference between an array name and a pointer
- From: Scott Fluhrer
- Re: [pointers and arrays]: The difference between an array name and a pointer
- From: Lew Pitcher
- Re: [pointers and arrays]: The difference between an array name and a pointer
- From: pemo
- Re: [pointers and arrays]: The difference between an array name and a pointer
- Prev by Date: Re: why is fread forgetting where its position?
- Next by Date: Re: sizeof
- Previous by thread: Re: C or C++ something else....
- Next by thread: Re: [pointers and arrays]: The difference between an array name and a pointer
- Index(es):
Relevant Pages
|