Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Jun 4, 2001

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 << 
Rajesh Chathapuram
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date