Array assignment without square brackets

I am working on an assignment that asks for a single statement to satisfy the following:

Without using the fp pointer, and without using square brackets, set the fourth element (i.e., the one at index 3) of the fish array to have the value "salmon".


Prior to this portion of the assignment, a 5 element array - fish - was created as well as *fp which points to fish.

I can only think of one possible way to assign "salmon" to fish[3] without square brackets. One would be to create another pointer that points to the first element, and then move the pointer to point at the 4th element. Unfortunately, this is not a single statement.

Is there something I'm missing?

Thank you.
The thing you are missing is that in C (and C++) that square brackets are syntactic sugar for pointer arithmetic.

    a[ 5 ]    ==    *(a + 5)

Hope this helps.

PS. If you want to be extra weird, you can also say

    5[ a ]

LOL.
Ahh I can't believe I forgot that.. I guess it's time to review pointers. Thank you for your help!
Yer welcome. It's the stupid stuff that's the weirdest in C and C++. (And the 'funest'.)
Topic archived. No new replies allowed.