Howdy all.

I'm having an issue tackling my assignment. my givens are I have an int pointer, which is supposed to point to an array of values. This pointer is in a private part of my class. However, I have a specific set of values I want to pass in, with a particular order from my main program.

these values are such: {5,3,6,8,4,2,9,1,10,7}

I thought, well, I could create an array in my main to store these values, then pass these values manually through a set function to the array in my class. which seems like there might be a more elegant solution, especially if I were to have to deal with this on a larger scale.

Any suggestions, questions, or help is much appreciated.

5 Years
Discussion Span
Last Post by Labdabeta

Any array is just a pointer to its first value, followed by allocated memory for the remaining values. As such this will work:

int myArray[]={5,3,6,8,4,2,9,1,10,7};
int *pntrToMyArray=myArray;
//at this point myArray and pntrToMyArray are exactly the same.
//note also that you can pass myArray directly to a function that uses int* as a parameter type
//if you need to make a copy of the array you will need a loop
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.