Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Working with adress of a pointer in a function

I have a function which receives an address of a pointer to an array, I want the function to iterate that array, how exactly should I write the function’s code?

example of the function, and the function’s call:

int example(int** arr, int n){}


k = example(&arr, n);

Using *arr, gives me the address of the first object in the array, using **arr gives me the value of the first object in the array.
But how do I access the next objects of the array is what I’m struggling with, let’s say I want to iterate through the array in a for loop for example.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just treat *arr as an array

int *array = *arr;
for(int i = 0; i < n; i++)
{
    // do something with array[i];
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading