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

ruo pu koh
ruo pu koh
2,669 Points

Confusing example.

There's so many "sphere"s littered throughout the code it's so hard to follow.

In the makeSphere function, we're creating a Sphere called sphere?

Why does a sphere have 3 centers anyway?

1 Answer

Gwenaël Magnenat
Gwenaël Magnenat
14,617 Points

I will try to answer with what I understood. In the makeSphere function you create a sphere with the Sphere struct and we return the sphere created at the end of the function to be used in the program. A sphere has 1 center defined by 3 coordinate values in a 3D space (x, y, z). It defines where the sphere is placed. In this example, the center is an array with the 3 values. That's why he defines a pointer that can point to each value of the center array. (ball.center[0], ball.center[1], ball.center[2])

I hope it helps..