#include <stdio.h>
int main() {
unsigned long long int num = 285212672; //FYI: fits in 29 bits
int normalInt = 5;
printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);
return 0;
}
Çıktı:
My number is 8 bytes wide and its value is 285212672l. A normal number is 0.
Bu beklenmedik sonucun unsigned long long int
yazdırılmasından kaynaklandığını varsayıyorum. Bir işaretsiz long uzun int'i nasıl
printf()` yaparsınız?
ll (el-el) uzun-uzun değiştiricisini u (işaretsiz) dönüştürme ile kullanın. (Windows, GNU'da çalışır).
printf("%llu", 285212672);
Bunun bir yolu VS2008 ile x64 olarak derlemektir
Beklediğiniz gibi çalışıyor:
int normalInt = 5;
unsigned long long int num=285212672;
printf(
"My number is %d bytes wide and its value is %ul.
A normal number is %d \n",
sizeof(num),
num,
normalInt);
32 bit kod için, doğru __int64 biçim belirtecini %I64u kullanmamız gerekir. Yani şöyle olur.
int normalInt = 5;
unsigned __int64 num=285212672;
printf(
"My number is %d bytes wide and its value is %I64u.
A normal number is %d",
sizeof(num),
num, normalInt);
Bu kod hem 32 hem de 64 bit VS derleyicisi için çalışır.