pointer question

Doug Gwyn gwyn at brl-vgr.ARPA
Fri Apr 6 08:18:29 AEST 1984


What you say is true but your example (p = p + 4) may be confusing.
If p is declared as a pointer to a 4-byte something, then
	++p;
and
	p = p + 1;
are equivalent.
	p = p + 4;
on the other hand makes the pointer point to the 4th something after
what it used to point to.  I think you meant using things like int p's:
	int	p;
	p = p + 4;
	do something with *(something *)p;
which is a (not recommended!) way to use an int as a pointer to
something.  If p is properly declared, then you would have had to
write your example in a way that makes the shenanigans obvious:
	something	*p;	/* 4 bytes per something */
	p = (something *)((int)p + 4);



More information about the Comp.lang.c mailing list