hi i m new here!! now i got a problem ... I need a number not less than 13digits to assign to a variable. which data type should i use? i tried, (it might be wrong), "long long int " n still i got stuck!! help me out
hi i m new here!! now i got a problem ... I need a number not less than 13digits to assign to a variable. which data type should i use? i tried, (it might be wrong), "long long int " n still i got stuck!! help me out
a long long int contains 64bit so there is a number range of 9223372036854775807 to -9223372036854775807.
13 digits shouldn't be problem for long long int.
i m using gcc v4.1.2. and my piece of code is like this
<code>
long long int x= 13131313131313;
printf("%lld", x); // have also tried %ld.
</code>
And sizeof says 8.
Last edited by HzTzr; 02-13-2009 at 08:14 AM.
Output: FFFFFFFFFFFFFFFFCode:#include <stdio.h> int main() { unsigned long long ll = 0xFFFFFFFFFFFFFFFF; printf("%llX\n", ll); return 0; }
Output: 18446744073709551615Code:#include <stdio.h> int main() { unsigned long long ll = 0xFFFFFFFFFFFFFFFF; printf("%llu\n", ll); return 0; }
I m so sorry for my stupidity!!! actually i am using lots of C compiler. I am currently using Dev-C++ 4.9.9.2 and i found out that it uses gcc v3.4.2 (mingw-special). (Sorry for losing your time). I tried your last code with this compiler and it prints 4294967295. help me out !!!!
That is becasue gcc-mingw uses an older C-library, so the printf format for long long is "%I64d" rather than "%lld".
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thank you very much!!! It works .... but may i know what is this "%I64d"... where can i learn more about format specifiers??? Thank you!!
You may want to have a look here:
http://msdn.microsoft.com/en-us/libr...dc(VS.71).aspx
for example. Since gcc-mingw is using Microsoft's C library, the relevant generation of the MSDN documentation is what you need - I'm not sure if that's the exact right version, but it's at least 99% right.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks again... a LOT Mr. Kernel hacker !! n many thanks to Elysia too!!! I m feeling much better now!!!
In C99, yes. HzTzr, compile your program with the -std=c99 option.Originally Posted by Elysia
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Only because the gcc-mingw maintainers hasn't produced a (stable) version of gcc-mingw for later versions than 3.4.x. But of course, it is still not GCC's fault for what is in a third party library, any more than it is the fault of a game that a particular implementation of OpenGL causes bad drawing on particular models of graphics card, right?
After all, the COMPILER can not fix the libraries it links to.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.