I'm hoping this will turn out to be a simple question. I'm looking at some C++ code where it's passing an array of structs to a method, example:
dosomething(arrayOfStructs + n);
The array was initialized at 256 items, and prior to calling the example method, it performs some work which populates the array with some items. The variable n, in this context, represents the number of items currently in the array.
I have no idea what the n variable does for the method being called, or even possibly to the array itself. The only thing I can think of is the number following the array is resetting the array size somehow. I could be totally off on that one.
I'm trying to follow the C++ code and try something similar in JavaScript. I am stuck on this n variable following the array.
arrayOfStructsdecays to a pointer to the 1st element. Addingnto this pointer will point to thenth element.arrayOfStructs[n](since you saidnis the number of items in the array). Or maybe you meant the number of items already filled in, in this case it's just pointing to the first element not yet filled in (again,arrayOfStructs[n]). We would need a bit more context of both the calling code and thedosomethingfunction to understand what a suitable representation in JavaScript would be, because those concepts cannot be translated 1:1 as JS doesn't have pointers. But you can imaginearr + xas&arr[x].arrayOfStructsandnas separate variables to the function.