[pointers and arrays]: The difference between an array name and a pointer



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?

.



Relevant Pages

  • Re: [pointers and arrays]: The difference between an array name and a pointer
    ... No. p stores an array 6 of characters. ... but it can often be treated /as if/ it were a pointer. ...
    (comp.lang.c)
  • Re: Java access speed (database or arrays)
    ... query the database once, store the information into an array, and that ... You can cluster/farm app servers more easily than data stores, but data stores can be scaled pretty high and have awesome built-in caches. ... Something similar pertains to information simultaneity, information latency and cognitive information processing. ...
    (comp.lang.java.programmer)
  • Re: Storing large arrays in a table
    ... table in this database stores what training needs to be carried based ... array and read the array. ... This worked fine until i hit the 255 char ...
    (comp.databases.ms-access)
  • Re: BASIC programming, random# and arrays.
    ... This stores the random numberin an array, then goes back and checks the ... This picks numbers from 1-10, randomly, and stores into N ... REM GENERAL PURPOSE SHUFFLE ... 10 DIM USED$,CHECK$,SUCCESS$,SHUFFLE ...
    (comp.sys.atari.8bit)
  • Re: BASIC programming, random# and arrays.
    ... This stores the random numberin an array, then goes back and checks the ... This picks numbers from 1-10, randomly, and stores into N ... I'm trying to figure out a really slick way of handing out a set of random ... numbers without duplicating. ...
    (comp.sys.atari.8bit)