#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];
}
添字のみを使用して、2 次元配列の要素を多数参照するプログラムを作成する必要があります。これは実際には 2 部構成のプロジェクトですが、私は最初の部分だけを正しく作成することに関心があります。2 番目の部分ではポインターを使用できますが、今のところ、"添え字" (インデックス?) のみを対象としています。進め方について何かアドバイスはありますか?
Volkan İlbeyli のおかげで、最初のパートを無事に完了できました。私は今、2番目の部分に進んでいます:
ポインターとポインター演算を使用して、2 次元配列の要素を多数参照するプログラムを作成する必要があります。これが私がこれまでに持っているものです:
#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);
}
}
}
私は最初の部分を完了し、現在次の部分に取り組んでいます。何か見逃していないか知りたいだけです。コードは正常に機能し、プログラムも正常に機能します。ポインターは私の強みではなく、インターネットで答えを見つけるのに多くの時間がかかりました. ポインターと「ポインター演算」に関する技術的な観点を求めています。