C++ simple sizeof difference between char array and char pointer

后端 未结 4 1227
难免孤独
难免孤独 2020-12-22 06:26
char * test = \"test\";
cout << sizeof(test);


char test2[] = \"test\";
cout << sizeof(test2);

Running this on visual studio 2010, why

4条回答
  •  攒了一身酷
    2020-12-22 06:55

    The first one displays the size of the pointer, not the array. In the second case, you are displaying the size of the array.

提交回复
热议问题