U
U
unclechu2014-07-07 21:44:55
C++ / C#
unclechu, 2014-07-07 21:44:55

How to work with a pointer to a dynamic array in "C"?

Let's say this piece of code:

float *arr;
arr = malloc( 16 * sizeof(float) );
arr[0] = 1.0;
arr[1] = 1.5;
arr[2] = 2.0;

And now I need to pass a memory reference from arr to the function, so that I can also work with the array from the function:
arr[3] = 1.0;
arr[4] = 1.5;
arr[5] = 2.0;

How to do it right? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Taratin, 2014-07-07
@unclechu

void workwitharray(float *array){
array[3] = 1.0;
array[4] = 1.5;
array[5] = 2.0;
}
workwitharray(arr);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question