Skip to content

Latest commit

 

History

History
70 lines (40 loc) · 2.7 KB

CppSizeof.md

File metadata and controls

70 lines (40 loc) · 2.7 KB

 

 

 

 

 

 

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'; }

 

 

 

 

 

sizeof being a compile-time operator

 

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"); }