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 trialAndrey Pushkin
181 PointsCan i always use arrays without fixed length?
So, i tried to use 2 constructions:
int my_array[2] = {1,2}; and int my_array[]={1,2};
My code worked correctly in same times. Can i always use second way? In what cases i have to use fixed length of array?
1 Answer
Stone Preston
42,016 Pointsyou can only leave the length of the array out if you use an initializer, which is the part that has the curly braces and the values of the array inside (int my_array[]={1,2}
). if you dont use an initializer, you have to provide the length of the array (int my_array[2];
);