Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointers

Status
Not open for further replies.

y2k1981

Programmer
Aug 2, 2002
773
IE
Can somebody help out a beginner here?

Code:
int a[5], *p;

Does the pointer p have any association with the array a or would I have to add an extra line with something like
Code:
*p = &a[0];

I would have thought that they don't have any association, seing that you could declare two ordinary variables eg
Code:
int a, b;
and they wouldn't have any association with each other but in a book I've been reading lately it implied that *p would be a pointer to the array a.

Can somebody clarify for me?
 
Code:
int *p;   /* pointer to int. */
int iarr[5];   /* array of int. */

p = iarr;   /* same as p = &iarr[0]. */
*p = 123;   /* same as p[0] = 123, *&p[0] = 123, and iarr[0] = 123. */
(*p)++;   /* the value stored at the address pointed to by p is increased by 1. i.e. 124. */
p++;   /* now p is refer to iarr[1]. */
/* in expressing the array, we can like this. */
2[iarr] = 912;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top