bate's blog

調べたこと実装したことなどを取りとめもなく書きます。

配列の基礎

配列を引数で受け取り、関数内で操作するサンプルを作って機能を確認。
基礎が出来ていない。
エプソンが出してる Endeavor Na01 mini が気になる。

#include <iostream>

using namespace std;

void add( int array[][2] )
{
	for( int i = 0; i < 4; ++i )
	{
		for( int j = 0; j < 2; ++j )
		{
			++array[i][j];
		}
	}
}

void disp( int array[][2] )
{
	for( int i = 0; i < 4; ++i )
	{
		for( int j = 0; j < 2; ++j )
		{
			cout << array[i][j] << " ";
		}

		cout << endl;
	}
}


int main()
{
	int a[4][2] =
	{
		{ 0, 1 },
		{ 2, 3 },
		{ 4, 5 },
		{ 6, 7 }
	};

	cout << "before add" << endl;
	disp( a );
	cout << endl;

	add( a );

	cout << "after add" << endl;
	disp( a );
	cout << endl;

	return 0;
}