String class e char in C++ -
String class e char in C++ -
when have
char anything[20]; cout << sizeof anything;
it prints 20.
however
string anymore; cout << sizeof anymore; // prints 4 getline(cin, anymore); // let's suppose type more 1 hundred characters cout << sizeof anymore; // still prints 4 !
i understand how c++ manages this. thanks
sizeof
compile-time construct. has nil runtime, rather gives fixed result based on type passed (or type of value passed it). char[20] 20 bytes, string might 4 or 8 bytes or whatever depending on implementation. sizeof isn't telling how much storage string allocated dynamically hold contents.
c++
Comments
Post a Comment