devxlogo

Calculate the Sizes of Data Types at Runtime

Calculate the Sizes of Data Types at Runtime

The size of the int, char, long, or short depends on what operating system and compiler version you are using. The same applies for short and long data types.

The usual method of determining size is to use the sizeof() function to find the number of bytes each data type occupies. But sizeof() is done at compile time, not at runtime.

The following code fragment calculates the number of bits in each of the above data types at runtime (repeat by changing i to long, short, char, etc.):

 main(){  int i = 1;  int count = 0;  while (i<<1)   count++;  cout <<

See also  5 Strategies for Supercharging Your CRM
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist