just wondering the difference between the presence of the last comma in the array, if there is any at all
>> [1,2,3]
=> [1, 2, 3]
>> [1,2,3,]
=> [1, 2, 3]
The second array still works, no exception raised
Thanks
You can declare an array of arrays (a "multidimensional" array) by following the array declarator with a list of bracketed constant expressions in this form: type-specifier declarator [ constant-expression ] [ constant-expression ] ...
An array is a variable that can store multiple values. For example, if you want to store 100 integers, you can create an array for it. int data[100];
One-Dimensional Arrays: type declares the element type of the array. The element type determines the data type of each element that comprises the array. Like an array of integers, we can also create an array of other primitive data types like char, float, double, etc., or user-defined data types (objects of a class).
A definition of an identifier is a declaration for that identifier that: As you noted yourself the memory for the array is reserved in data section then you have a declaration of an array that at the same time is a definition. Save this answer.
There's no difference. In Ruby, you're free to add a trailing comma to an array. It makes syntax like this:
a = [
1,
2,
3,
]
A bit nicer, in some cases (e.g., if you want to add an element, you simply add a 4,
line and don't have to worry about checking for a comma on the last line).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With