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

后端 未结 4 1202
难免孤独
难免孤独 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:52

    on a 32-bit system, the size of a pointer is 32 bits or 4 bytes and therefore, size of test is 4. On the other side, test2 is an array with a NUL terminating character and it's size is 5.

提交回复
热议问题