0

If I declare an array say:

int arr[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};

Now when I use the following command:

cout<<arr;
cout<<*arr;

Both of the above statements give me the address of 1. How does this work?

Should not *arr print elements 1,2,3 and 4?

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
wrightboy
  • 49
  • 1
  • 5
  • _How are elements stored in a 2-D Array?_ AFAIK it's not specified how they are stored. It's an implementation detail and can differ between different compilers. Most compilers store the elements of `int arr[3][4]` and `int arr[12]` in the same way but you shouldn't write code that depends on this detail. – Thomas Sablik Feb 08 '20 at 14:13
  • Related, maybe even duplicate: https://stackoverflow.com/questions/22983734/multiarray-and-multiarray0-and-multiarray0-same/22984784#22984784 Did you try printing a 1D-array like this? It doesn't work either, you can't print arrays like that. – Lukas-T Feb 08 '20 at 14:14

0 Answers0