Monday, April 7, 2008

Use of __int64 variable in C++

You can use the 64 bit variable if you know how to use it. If you are a user of Visual Studio 6.0(VC6) then you can use __int64 variable easily. This is the additional data type of VC6. __int64 support both signed and unsigned data type. If it is signed then it can hold 2^63 - 1 at max. For unsigned it can hold 2^64 - 1.

This is an example of how to declare a __int64 variable and print it. Remember while printing its not %d, its %I64d. Just remember this while printing.

__int64 i = -1234567890123456789; // a negative number.

You can use unsigned for another extra bit to extend. But you can't use any negative number in this case. Also remember this %I64u to denote the unsigned number.

unsigned __int64 i = 1234567890123456789;

If you are using gcc compiler, then you have to use long long as the variable name and while printing, you have to use it %lld instead of %I64d.

long long i = -1234567890123456789; // a negative number.

Similar for unsigned long long below example with %llu when needs to print.

unsigned long long i = 1234567890123456789;

Mainly these types of variable commonly used by the programmer of ACM programming contest. But when sometimes it requires another more large number, like few thousands digits number, that cases the use their custom defined number class that can handle arithmetic operation with very long number.


Anonymous said...

Thank you for posting this. I couldnt print this type and the VC6 helpfiles were of little value.

A lucid and informative blog. Read thoroughly and appreciated!

Sandeep Kori said...

It was really helpfull...thanks and keep posting nice stuffs.


Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...