pointer increment

Shiping Zhang ping at cubmol.BIO.COLUMBIA.EDU
Sun Aug 13 05:43:54 AEST 1989


In article <484 at eagle.wesleyan.edu> dkonerding at eagle.wesleyan.edu writes:
>
>        Hi folks.  I'm a confused beginner C programmer who'd like to
>understand pointer variables a bit better.  I have a small program.  I've done
>the following:  int *ptr;
>
>        Now, say I make ptr=1000 or hex 3e8.  I want to add one to the ptr, to
>make it point to 1001, or hex 3e9.  Every time I do a ptr=ptr+1, it becomes
>3ec.  How can I simply increment ptr by one?

Points hold the locations or addresses of the varibles they point to.
So they change in units of the size (in bytes) of the varible type they
point to. On most of machines, the int size is 4 (bytes,or 32 bits).
So increasing a point to int by 1 advances the point to the address of
the next int, which is 4 bytes further, therefore the value of the point
is increased by 4.


-ping



More information about the Comp.lang.c mailing list