更新时间:2022-10-17 10:15:02
的printf(无符号:%U \\ N,uEntry);
// ^^
您必须使用%U
符告诉的printf
运行时的 uEntry
是 unsigned int类型
。如果你使用%d个
的的printf
函数会期待一个 INT
,从而reinter preT你输入回一个签名的值。
Actually I've (probably) a "simple" problem. So I don't know how to cast a signed integer to an unsigned integer.
My code :
signed int entry = 0;
printf("Decimal Number : ");
scanf("%d", &entry);
unsigned int uEntry= (unsigned int) entry;
printf("Unsigned : %d\n", uEntry);
If I send the unsigned value to the console (see my last code line), I always get back an signed integer.
Can you help me?
Thanks a lot!
Kind regards, pro
printf("Unsigned : %u\n", uEntry);
// ^^
You must use the %u
specifier to tell the printf
runtime that the uEntry
is an unsigned int
. If you use %d
the printf
function will expect an int
, thus reinterpret your input back to a signed value.