sizeof is a compile-time operator to determine the size of a data type in bytes.
#include <iostream> int main() { std::cout << "bool size: " << sizeof(bool) << '\n' << "int size : " << sizeof(int) << '\n'; }
Because sizeof is a compile-time operator, one can use on it:
int main() { static_assert(sizeof("") == 1,"The sizeof of a string is its number of characters + 1"); static_assert(sizeof("1") == 2,"The sizeof of a string is its number of characters + 1"); static_assert(sizeof("12") == 3,"The sizeof of a string is its number of characters + 1"); static_assert(sizeof("123") == 4,"The sizeof of a string is its number of characters + 1"); static_assert(sizeof("1234") == 5,"The sizeof of a string is its number of characters + 1"); }