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

devx-admin

Share the Post: