#include <iostream>
#include <time.h>
using namespace std;
void my_func();
int main()
{
float start_time = clock();
cout << "Starting time of clock: " << start_time;
cout << endl << endl;
for (int i = 0; i < 100000; i++)
{
my_func();
}
float end_time = clock();
cout << "Ending time of clock: " << end_time;
cout << endl << endl;
}
void my_func()
{
int my_array[5][5];
}
I need to write a program that does a large number of references to elements of a two-dimensional array, using only subscripting. This is really a two-part project, but I'm only concerned with getting the first part right. The second part allows the use of pointers but for now, I am only subject to "subscripting" (indices?). Any advice on how to proceed?
I have successfully completed the first part thanks to Volkan İlbeyli. I am now moving on to the second part:
I need to write a program that does a large number of references to elements of a two-dimensional array, using pointers and pointer arithmetic. Here's what I have so far:
#include <iostream>
#include <time.h>
using namespace std;
void my_func();
int main()
{
float start = clock();
for (int i = 0; i < 100000; i ++)
{
my_func();
}
float end = clock();
cout << "Ending time of clock: " << (end - start) / ((double)CLOCKS_PER_SEC);
}
void my_func()
{
int my_array[10][10];
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
*(my_array+i+j);
}
}
}
I have done the first part and now I am working on the next part. I just want to know if I've missed anything. The code works fine and so does the program. Pointers are not my strongpoint and it took me a lot of time on the Internet to find my answers. Asking for a technical standpoint now on pointers and "pointer arithmetic".