#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;
}
출력:
My number is 8 bytes wide and its value is 285212672l. A normal number is 0.
내가 이 예상치 못한 결과가 반환되었습니다) 는 서명되지 않은 long long int '이' solaris. 인쇄면이. Printf () '는 서명되지 않은 long long int' '' 어떻게 해야 할까요?
긴 긴 수정자의 경로재설정 (ll (엘 (el) 와 u (무기명) 변환. (Windows 에서 작동됨, GNU).
printf("%llu", 285212672);
라이브러리를 사용할 수 있는 등 추상형데이터타입 안티파스콜라 시도할 수 있습니다 ',' ',' 촉각 'int32_t int64_t uint64_t. 이 같은 매크로를 사용할 수 있습니다.
uint64_t x;
uint32_t y;
printf("x: %"PRId64", y: %"PRId32"\n", x, y);
이는 guaranteed" "; 같은 문제가 되지 않도록 긴 긴 'unsigned' 긴 ',' 로 제공하십시오 너회가 don& # 39 등), 이후 각 데이터 타입이 없는 시용되는 비트가 어렵지 않다.
',' -> %d. int '대한'
'%u' ->. unsigned int '대한'
'%ld' ->. '대한' long int
'%lu' ->. "에 대한 서명되지 않은 long int '
',' -> %lld long long int '대한'
',' -> %llu 서명되지 않은 long long int '대한'
이는 %llu doesn& # 39, t, t 처리하십니까 64 비트 정수 및 %d. Windows 에서 제대로 can& # 39. 내가 사용하는 대신, ll groupx it& 제안하세요 PRIu64 you& # 39 의 이동형이든지 # 39 와 Linux 로 잘 알려져 있다.
이 시도하시겠습니까 대신:
#include <stdio.h>
#include <inttypes.h>
int main() {
unsigned long long int num = 285212672; //FYI: fits in 29 bits
int normalInt = 5;
/* NOTE: PRIu64 is a preprocessor macro and thus should go outside the quoted string. */
printf("My number is %d bytes wide and its value is %" PRIu64 ". A normal number is %d.\n", sizeof(num), num, normalInt);
return 0;
}
출력입니다
My number is 8 bytes wide and its value is 285212672. A normal number is 5.
이는 '와' 이 '는' %I64u %llu Linux 에서 Windows 에서
하지만 나는 그것을 발견, Windows 2000년, t # 39 doesn& 작업하십시오 좁히어 것으로 버그 잡깐!
확실히 다중-플랫폼 * 사람이 없고 마련하지 솔루션을 통해 덮어쓰기/추가 내거냐 & # 이후 십 년 동안 (해당] 2008년, 그래서 내가 불지옥으 128539;. Plz 업보테. (깨달았습니다. 전 알렉스랑 사귀잖아요)
How to use.
#include <stdlib.h> /* lltoa() */
// ...
char dummy[255];
printf("Over 4 bytes: %s\n", lltoa(5555555555, dummy, 10));
printf("Another one: %s\n", lltoa(15555555555, dummy, 10));
OP 의 예:
#include <stdio.h>
#include <stdlib.h> /* lltoa() */
int main() {
unsigned long long int num = 285212672; // fits in 29 bits
char dummy[255];
int normalInt = 5;
printf("My number is %d bytes wide and its value is %s. "
"A normal number is %d.\n",
sizeof(num), lltoa(num, dummy, 10), normalInt);
return 0;
}
포맷 스트링 인쇄하십시오 달리, 이 번호요 작동됨 %lld '에서' 의 32 비트 mgcc Windows. 가져다줄래요
뭐, 이를 통해 하나의 방법은 컴파일하십시오 VS2008 x64
이 런입니다 것과 같은 것으로 보고 있다.
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 비트 코드를 사용하여 _int64 수정하십시오 %I64u 지정자와 포맷하십시오 필요하다. 되도록.
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);
이 코드는 32 비트 및 64 비트 VS 컴파일러와의 모두 효과적입니다.