C + + dynamic assignment two-dimensional array new two-dimensional array

Source: Internet
Author: User

#include"stdafx.h"#include<iostream>using namespacestd;int_tmain (intARGC, _tchar*argv[]) {    //set up an array of 16 rows and 5 columns    int**p =New int*[ -];//allocating heap Memory 16 x int*     for(inti =0; I < -; i++)//allocate heap memory to each int*P[i] =New int[5]; //assign a value to this array    intK =0;  for(inti =0; I < -; i++)    {         for(intj =0; J <5; j + +) {P[i][j]= k++; }    }    //output two-dimensional arrays     for(inti =0; I < -; i++)    {         for(intj =0; J <5; j + +) {cout<<p[i][j]<<"\ t"; } cout<<Endl; }    //Release     for(inti =0; I < -; i++)        Delete[] p[i]; Delete[] p; System ("Pause"); return 0;}

C + + dynamic assignment two-dimensional array new two-dimensional array

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.