Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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..