Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在c+中访问二维指针数组中的值+;_C++_Arrays - Fatal编程技术网

C++ 在c+中访问二维指针数组中的值+;

C++ 在c+中访问二维指针数组中的值+;,c++,arrays,C++,Arrays,我想声明具有可变大小的二维数组。 我写了下面的代码,但出现了一些问题 int **p2DArray; p2DArray = new int*[target_counter_new]; for (int i = 0; i < target_counter_new; ++i) { p2DArray[i] = new int[target_counter_old]; } for(int i_oghli=0;i_oghli<target_counter_new;

我想声明具有可变大小的二维数组。 我写了下面的代码,但出现了一些问题

int **p2DArray;
p2DArray = new int*[target_counter_new];
for (int i = 0; i < target_counter_new; ++i)
    { 
   p2DArray[i] = new int[target_counter_old];
     }


for(int i_oghli=0;i_oghli<target_counter_new;i_oghli++)
    for(int j_oghli=0;j_oghli<target_counter_old;j_oghli++)
    {
         p2DArray[i_oghli][j_oghli]=i_oghli+10;
         cout<<p2DArray[i_oghli][j_oghli];
    }
int**p2DArray;
p2DArray=新整数*[目标计数器新];
对于(int i=0;i)\include
使用名称空间std;
const int target_counter_new=4;
const int target_counter_old=4;
int main(){
int**p2DArray;
p2DArray=新整数*[目标计数器新];
对于(int i=0;i对于(int i_oghli=0;i_oghli“但出了点问题!”您能说得更具体一点吗?是的,p2Array中的值与其地址相关,而不是i_oghli不确定这意味着什么,对我来说,它按预期工作:变量的含义是什么?:-).ye kem behtar benvis Barardary您的代码在c++98、c++11、c++14上运行良好。没问题,很高兴这对您有所帮助。
#include <iostream>
using namespace std;

const int target_counter_new = 4;
const int target_counter_old = 4;
int main() {
    int **p2DArray;
    p2DArray = new int*[target_counter_new];
    for (int i = 0; i < target_counter_new; ++i) { 
       p2DArray[i] = new int[target_counter_old];
    }

    for(int i_oghli=0;i_oghli<target_counter_new;i_oghli++) {
        for(int j_oghli=0;j_oghli<target_counter_old;j_oghli++) {
             p2DArray[i_oghli][j_oghli]=i_oghli+10;
             cout<<p2DArray[i_oghli][j_oghli] << " ";
        }
        cout << endl;
    }
    // don't forget to delete the array
    for (int i = 0 ; i < target_counter_new; ++i) {
        delete [] p2DArray[i];
    }
    delete [] p2DArray;
    return 0;
}