Array as array[n] and as pointer array*

后端 未结 2 1344
礼貌的吻别
礼貌的吻别 2021-01-14 07:22

What is the difference when array is declared as array[n] or as pointer array* according to example below? I guess that for example both \'a\' and \'c\' point at the first e

2条回答
  •  日久生厌
    2021-01-14 07:57

    The difference between the following two lines:

    int g[10];
    

    and

    int* h = new int[10];
    

    is that the second is dynamically-allocated, whereas the first is statically-allocated.

    For most purposes, they are identical, but where in memory they end up living is different.

提交回复
热议问题