Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Objective-C Basics (Retired) Pointers and Memory Structs

Ryan Jin
Ryan Jin
15,337 Points

Why it is *c

Why it is *c for an array. I thought float *c is a pointer that points to a float variable

Stepan Ulyanin
Stepan Ulyanin
11,318 Points

Because in C along with C++ and some other languages the array name is a pointer to the memory address of the first element of the array;

int my_array[3] = {1, 2, 3}; // creates an array

printf("%04x", array); //will print the memory address of my_array[0] which is 1

that's why they pass the pointer to a float which is the first element of the array, coming from there you can just use the subscript operator to de-reference it (c[0] or c[1]) - [ ] is the subscript operator and it will display the value that is stored at the memory address connected to the array through the pointer;

I hope it helps!