sizeof char* array in C/C++

后端 未结 6 727
旧巷少年郎
旧巷少年郎 2021-02-14 07:57

There are plenty of similar inquires, but in my case I don\'t understand what isn\'t working:

int mysize = 0;
mysize = sizeof(samplestring) / sizeof(*samplestrin         


        
6条回答
  •  眼角桃花
    2021-02-14 08:22

    you are asking the size of a pointer on a char. So I guess you're using a 32bit system.

    If you're using C++, use std::string :

    std::string samplestring("Hello world");
    std::cout << samplestring.size() << std::endl;
    

提交回复
热议问题