Programatically Finding Integer Size

Jim Hayward jimhayward at earthlink.net
Sat Oct 11 05:58:00 UTC 2003


On Fri, 2003-10-10 at 22:28, Robert L Cochran wrote:
> I'm learning C++. Can someone tell me the accepted way to 
> programatically determine the size of integers on a given system using C++?

Just like C use the sizeof operator...

cout << "sizeof (int) is " << sizeof (int) << " bytes.\n";

If you are using sizeof with a type enclose the type in parentheses. If
you are using sizeof with a variable name the parentheses are optional. 


> (The learning process seems to be slower than I want it to be. By the 
> time I get to be good with C++, it will probably be obsolete.)

It always happens that way. Right after you get good at something some
"expert" will come a long and decide it is obsolete. :-/


Regards,
	Jim H







More information about the test mailing list