设为首页 加入收藏

TOP

C++二维动态数组
2014-11-14 15:15:24 】 浏览:9128
Tags:二维 动态

  #include "stdafx.h"


  #include


  using namespace std;


  int main()


  {


  int r; //行数


  int c; //列数


  cout<<"Please input the number of rows of the dynamic array: ";


  cin>>r; //输入行数


  cout<<"Please input the number of columns of the dynamic array: ";


  cin>>c; //输入列数


  //创建二维动态数组


  int **p=new int*[r];


  for(int i=0;i


  {


  p[i]=new int[r];


  }


  cout<<"The array named p["<


  //循环赋值


  int temp;


  for(int i=0;i


  {


  for(int j=0;j


  {


  cout<<"Please input a value of p["<


  cin>>temp;


  *(*(p+i)+j)=temp; //寻址赋值


  }


  }


  //循环显示


  cout<<"The dynamic array is "<


  for(int i=0;i


  {


  for(int j=0;j


  {


  cout<<*(*(p+i)+j)<<" "; //寻址读取


  }


  cout<


  }


  return 0;


  }


  编辑特别推荐:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇小议虚函数的原理 下一篇C++操作符重载不同方式区别

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目