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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.