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 trialIosif Skorohodov
1,126 PointsWhy do you have to use square brackets?
Do floating numbers have to be in square brackets?
1 Answer
Stone Preston
42,016 Pointsusing square brackets when working with arrays is just a part of the syntax. this style is common in many programming languages
in the code below, I declare an array of floats with a size of 3. the number that goes between the brackets is the length of the array, or the number of items it can hold:
float numbers_geeks_love[3];
I can then index that array using the arrays name followed by square brackets with the index of the array inside to add values to that array. indexes start at 0, so if I wanted to add a number to the first spot in the array I would use index 0, the second spot would be index 1, etc etc.
numbers_geeks_love[0] = 3.1415;
numbers_geeks_love[1] = 1.6180;