#include <iostream>
using namespace std;
int main() {
char a[][6] = { "hello", "hii" };
cout << a << ", " << *a << ", " << **a;
return 0;
}
OUTPUT : 0x7ffd1f44a20c, hello, h
Now, as we know that the array-name(in this case 'a') in case of 2D array points to the 1D array (in this case "hello"), *a will point to the element in that (1D array pointed by a) array and **a will give use the value pointed by *a. Now in this case i am little confused because of two reasoning:
- The output is right, since the value pointed by 'a' is "hello", and *a will print the value pointed by 'a'.
- The output is wrong, since *a itself is pointing the element inside 1D array and hence *a should have printed the address corresponding to the first element of 1D array pointed by a and the output should have been :
Expected output : 0x7ffd1f44a20c, address of h, h
Thank you very much for patience!