C
Cam
Hi everyone,
I am having trouble grasping the different syntax of pointers being used to
pass arrays between functions.
Am I right with the following:
....
int dog[8] // declares an 8 element array called dog whose elements are int
int *dog_ptr = dog // declares a pointer called dog_ptr that points to the
whole dog array
....
dog_ptr[3] // refers to the fourth element (0, 1, 2, 3) of the dog array
I believe that I have the third (dog_ptr[3]) line understood, but I cannot
understand how I can use a pointer to point to the whole array instead of
using a "for" loop to modify the whole array as individual elements.
I would really appreciate a fairly simple explanation of how I should use
these.
Thanks,
Cam
I am having trouble grasping the different syntax of pointers being used to
pass arrays between functions.
Am I right with the following:
....
int dog[8] // declares an 8 element array called dog whose elements are int
int *dog_ptr = dog // declares a pointer called dog_ptr that points to the
whole dog array
....
dog_ptr[3] // refers to the fourth element (0, 1, 2, 3) of the dog array
I believe that I have the third (dog_ptr[3]) line understood, but I cannot
understand how I can use a pointer to point to the whole array instead of
using a "for" loop to modify the whole array as individual elements.
I would really appreciate a fairly simple explanation of how I should use
these.
Thanks,
Cam