Path: utzoo!attcan!uunet!husc6!rutgers!columbia!cubmol!ping
From: ping@cubmol.BIO.COLUMBIA.EDU (Shiping Zhang)
Newsgroups: comp.lang.c
Subject: Re: pointer increment
Message-ID: <315@cubmol.BIO.COLUMBIA.EDU>
Date: 12 Aug 89 19:43:54 GMT
References: <484@eagle.wesleyan.edu>
Reply-To: ping@cubmol.UUCP (Shiping Zhang)
Organization: Dept. of Biology, Columbia Univ., New York, NY
Lines: 19

In article <484@eagle.wesleyan.edu> dkonerding@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