What's the difference among '0', '\0' and 0 with sizeof() and strlen()?
#include <iostream>
int main(int argc, char* argv[])
{
int pt[4] = {'0','\0',0};
std::cout<<"size of pt: "<<sizeof(pt)<<std::endl;
std::cout<<"strlen of pt: "<<strlen((char*)pt)<<std::endl;
}
the result is:
size of pt: 16
strlen of pt: 1
and when I change int pt[4] = {'0','\0',0}; to int pt[4] = {'\0','0',0};
the result is
size of pt: 16
strlen of pt: 0
Why?
No comments:
Post a Comment