I want to have some function like this:
My_function (bla bla bla, pointer_to_an_item_array)
I want to use "pointer_to_an_item_array" to store data
Suposse i have myarray1[10], or myarray2[10][20]
how can i pass the item 3 of myarray1 to store 1 data or the item 3 of myarray2 to store 20 data.
how can i do this ?
My_function(bla bla bla , & pointer)
pointer=data; case myarray1 (unidimensional)
pointer[1]=data ??? case myarray2 (bidimensional)
If you pass an item pointer, you can access *ptr or ptr[10]. The real question is how will you know whether a single element or an array was passed? And even more importantly, in what case such function is a logical solution?
I' simply want to fill data into my array.
Now I'm using an array returned by the function.... It spends more time...
If I'm sure what elements receive my function I think that I can write code to pass pointers.
Can you recommend me a link about it ?
Thanks
If you are writing something like a memset (a function that sets all bytes of an array to some value) you might want to pass pointers to the first and the last elements (or even better, one after last). That way your function can know what exactly to fill.