Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Run Time ask for size

How I can in run time ask from different computers about size of int.
0
Michael Vai
Asked:
Michael Vai
  • 3
  • 2
1 Solution
 
pellepCommented:
sizeof(int)
0
 
Michael VaiAuthor Commented:
Without sizeof(int)
0
 
abesoftCommented:
Seems like a strange request.  Why don't you want to use sizeof()?

Anyway, here it goes:

int sizeInBits;
for (sizeInBits = 1; (1u << sizeInBits) > 1; ++sizeInBits)
    cout << (1u << sizeInBits) << endl;
cout << "An int is " << sizeInBits << " bits" << endl;

This works under VC++.  I believe that the definition of << is standard enough for this to work on any compiler.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
abesoftCommented:
Sorry.  Should have written that as:

int sizeInBits;
for (sizeInBits = 1; (1u << sizeInBits) > 1; ++sizeInBits)
    ;
cout << "An int is " << sizeInBits << " bits" << endl;
0
 
Michael VaiAuthor Commented:
what means "1u"
0
 
abesoftCommented:
u = unsigned
l = long

You can tag a constant with either or both of these qualifiers.  In effect, we measured the size of an unsigned int, not an int.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now