Hi all.

I have code that looks like this:

``````void bubblesort (int arr[], string stringarr[])
{

for (int i=0;i<5;i++)
{
for (int j=0;j<i;j++)
{
if (arr[i] > arr[j])
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;

string strtemp=stringarr[i];
stringarr[i]=stringarr[j];
stringarr[j]=strtemp;
}
}
}
}``````

It is a bubble sort trying to find the highest value, with the string name attached to it.

For example, a=5, b=10, c=50, d=39.

How is it possible to clear all the variables and reset the code for another use in the program?

For example, if I encounter w=600, x=421, y=222, z=742 later on.

don't understand what you are trying to say. Variables a, b, c and d do not appear in the code you posted.

don't understand what you are trying to say. Variables a, b, c and d do not appear in the code you posted.

alright, so I have an array arr[] = { a, b, c, d } and city[] = { ny, la, mia, chi }I want to pass these two arrays through the function, where the highest value would be outputted (in this case, it would be c which is associated with mia.

Then, I want to call the function again with a different set of arrays. arr2[] = {w, x, y, z} with city2 = { ny, la, mia, chi } where the highest value would be z, chi.

How can I reset the values from the first function use so that everyone can be regular when using it a second time?? I hope that helped with the explanation.

The parameters of a function only exist as long as the function is executing. When the function has finished, its parameters disappear. They don't need to be "reset" before the second call. When you call the function, you provide the arrays it should work on, and the second time you call, you just provide different arrays it should work on and it will work on those arrays instead. Function parameters are not global variable that exist all the time, they simply take the values that are passed to the function when it is called, then can be used inside the function, and when the function is over, these variables disappear (literally). In your specific case, the parameters are arrays, so they are passed as pointers to the first element of the array, at every call, they are assigned to point to whatever array you provided when you called it.

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.