?? cpp2.cpp
字號:
#include <stdio.h>
#include <iostream.h>
//很重要,要想檢查到memory leaks
//一定要包括afx.h!
#include <afx.h>
void main()
{
//二維數組首指針
int **Dinamic2DArray;
Dinamic2DArray=NULL;
int k;
int j;
//輸入數組的行數
cout<<"Please Input the row number of the Array:";
cin>>k;
//輸入數組的列數
cout<<"Please Input the column number of the Array:";
cin>>j;
//動態分配空間
Dinamic2DArray=new int* [k];
for(int ii=0;ii<k;ii++)
Dinamic2DArray[ii]=new int[j];
int counter=0;
//給數組賦值
for(int m=0;m<k;m++)
{
for(int n=0;n<j;n++)
{
Dinamic2DArray[m][n]=counter;
//*(Dinamic2DArray[m]+n)=counter; 上一行也可以
counter++;
}
}
//輸出數組的內容
cout<<"the 2d array is:"<<endl;
for( m=0;m<k;m++)
{
for(int n=0;n<j;n++)
{
cout<<Dinamic2DArray[m][n]<<" ";
}
cout<<endl;
}
//注釋以下的代碼將會引起內存泄漏
/*
for(int i=k-1;i>=0;i--)
delete [] Dinamic2DArray[i];
delete [] Dinamic2DArray;
Dinamic2DArray=NULL;
*/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -