# \[CCALL/INTEROP\] Get a \`Ptr\` for the last (or arbitrary) element of an array

**URL:** <https://discourse.julialang.org/t/ccall-interop-get-a-ptr-for-the-last-or-arbitrary-element-of-an-array/111360>\
**Category:** General Usage\
**Tags:** question, ccall\
**Created:** [March 8, 2024, 2:39pm UTC](https://discourse.julialang.org/t/ccall-interop-get-a-ptr-for-the-last-or-arbitrary-element-of-an-array/111360 "2024-03-08T14:39:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 8, 2024, 2:39pm UTC](https://discourse.julialang.org/t/ccall-interop-get-a-ptr-for-the-last-or-arbitrary-element-of-an-array/111360/1 "2024-03-08T14:39:11Z")

</div>

Sorry, I tried to find it myself in documentation but was not able to find a good answer.

I want to wrap a C function that takes two pointers, one for the first element of an array, the other for the last element of the same array. I want to create such array in Julia (probably with `Vector`, the elements are an `isbits` `struct` I already created following the recommended translation rules) so Julia owns the memory, and then just pass the two pointers needed to the function (which will change the elements in the range). I have found no way to obtain a pointer to the last element of the Vector (or an arbitrary position) so I can pass it as the second argument of the C funcion.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 8, 2024, 2:44pm UTC](https://discourse.julialang.org/t/ccall-interop-get-a-ptr-for-the-last-or-arbitrary-element-of-an-array/111360/2 "2024-03-08T14:44:39Z")

</div>

Okay, it seems like the docs of CCall assume the reader knew about `pointer(array[, index])` or `Ref(array[, index])` my question now is which one should I use?

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 8, 2024, 3:19pm UTC](https://discourse.julialang.org/t/ccall-interop-get-a-ptr-for-the-last-or-arbitrary-element-of-an-array/111360/3 "2024-03-08T15:19:56Z")

</div>

Seems like `Ref(a, firstindex(a))` and `Ref(a, lastindex(a))` will do the job.
