c++ - How to represent multi-dimensional array in pointer format? -


this question has answer here:

for 1 dimensional array, have no problem accessing array element. example --

#include<typeinfo> #include<iostream> #include<vector> using std::cin; using std::cout; using std::endl; using std::vector; using std::string; int main() {         int a[3] = {1, 2, 3};         cout << *(a + 0);         return 0; } 

but when trying 2 dimensional array, getting output of kind --

#include<typeinfo> #include<iostream> #include<vector> using std::cin; using std::cout; using std::endl; using std::vector; using std::string; int main() {         int a[][3] = {1, 2, 3};         cout << *(a + 2);         return 0; } 

output --

0x7ffca0f7ebcc 

how can output 2(i 2 either row major or column major order, c++ follows row major array representation) in format described in 1st example?

this give third element of first row.

#include <iostream>     int main() {     int a[][3] = {1, 2, 3};     std::cout << *(*a + 2); } 

although might find a[0][2] easier understand.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -