View Single Post
Old 09-11-2015, 04:14 AM   #7
sickufully
Sir Krisk
FFR Veteran
 
sickufully's Avatar
 
Join Date: Dec 2007
Location: Vic, Australia
Posts: 930
Default Re: [University - C++ Programming] Filling an Array with RNG & Display Contents

This is what the teacher provided in terms of the second half of the program. I think it's asking to display the contents of each element in the array. I'm just trying to work out what the first line means (the Display function). I'm fairly certain I don't need to change anything in void Display(int *arrayData,...), but please let me know otherwise.

Code:
Display(/* Insert your function identifier here */, sizeof(/* Insert your
function identifier here */)/sizeof(int));
return 0;
}
void Display(int *arrayData, int numElements)
{
for (int counter = 0; counter < numElements; counter++)
{
std::cout << *(arrayData + counter) << std::endl;
}
return;
}
This is what I have written (clearly isn't correct cause it doesn't run):
Code:
Display(int randArray, sizeof(int randArray) / sizeof(int));
		return 0;
}

	void Display(int *arrayData, int numElements)
	{
		for (int counter = 0; counter < numElements; counter++)
		{
			std::cout << *(arrayData + counter) << std::endl;
		}
		return;
	}
I'm confused by the fact that Display has been initialised before Main and then it's then called twice, but once within Main and once again outside of it. Can someone explain this to me? More along the lines of what does the first Display call do?
__________________
sickufully is offline   Reply With Quote