C++基础三-数组
#include <iostream> using namespace std; int main() { //1.定义数组 /*int args[5] = { 1,2,3}; //数组不够5个元素,将被0填充 for ( int i =0 ; i< 5 ; i++) { cout << args[i] << endl; }*/ //2.数组名 /*int arr[5] = { 1,2,3,4,5 }; cout << sizeof(arr[0]) << endl; //统计数组某值的内存占用大小 cout << sizeof(arr) << endl; //统计数组的内存占用大小 cout << arr << endl; //统计数组内存首地址 cout << &arr[0] << endl; //统计数组某元素的首地址*/ /*//3.Find Max int arr[5] = { 30,20,40,10,50 }; int max = 0; for (int i = 0 ; i <5; i ++) { if ( arr[i] > max ){ max = arr[i]; } }d cout << "Max is :" << max << endl;*/ /*//3.多维数组 // 定义数组1 int arr[2][3] = { {0,2,3}, {4,5,6} }; // 定义数组2 int arr2[2][3] = {10,20,30,40,50,60}; arr[0][0] = 1; //修改元素 //遍历多维数组元素 for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { cout << arr[i][j]; } cout << endl; } for (int i1 = 0; i1 < 2; i1++) { for (int j1 = 0; j1 < 3; j1++) { cout << arr2[i1][j1]; } cout << endl; }*/ int arr2[2][3] = { 10,20,30,40,50,60 }; cout << sizeof(arr2) << endl; cout << (int)arr2 << endl; cout << (int)arr2[0] << endl; cout << (int)arr2[1] << endl; cout << (int)&arr2[1][0] << endl; cout << sizeof(arr2) / sizeof(arr2[0]) << endl; //行数 return 0; }