Clarification needed on Pointers/Arrays

alistair at minster.york.ac.uk alistair at minster.york.ac.uk
Wed Mar 1 20:24:39 AEST 1989


a is an array of pointers - not chars, in other words:
a is a pointer to a pointer
*a is a pointer
**a is a char

so passing it to foo1 and 'pretending' it is a pointer to a char does not
work.  So, b is not pointing to an array of chars, but an array of pointers,
but when the compiler encounters b+i it increments b to the next
byte address - somewhere in the middle of a pointer.

Also, what you really intended to print out was *(b + i), b + i is an
address - which is why you happened to get control codes printed - but
incremented by one each time.

In foo2 b is an address - the base address of an array of pointers.  On
your implementation (but see other discussions about sizes of pointers
in this topic) a char address is the same size as an array address -



More information about the Comp.lang.c mailing list