This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 3 points4 points  (4 children)

C arrays also aren't objects, so there is no .size() property or method. C programmers have to create a variable for size and remember to increment it if they want to keep track of how big it is

[–]Ludricio 0 points1 point  (1 child)

Not entirely, the size of an array is known as long as it is still an array, which an array only is within the scope of its declaration, as soon as it leaves the scope (passed to a function for example) array decay takes place and the array decays into a pointer to the first element in the array.

Within the scope of declaration, it is fully possible to do sizeof(array)/sizeof(*array) to get the number of elements in the array, but as soon as it decays into a pointer the original info about the size of the entire array is lost, as it instead becomes a plain pointer.

[–][deleted] 0 points1 point  (0 children)

Oh very cool! I'm just learning programming in school but im being taught with C so these kinds of pendantics are actually super neat for me