[英]how does c compiler handle unsigned and signed integer? Why the assembly code for unsigned and signed arithmetic operation are the same?
[英]how does c compiler represents unsigned integer internally
#include<stdio.h>
int main()
{
int num=0,num1;
do
{
num++;
num1=num+1;
}while(num1>num);
printf("\nthe largest +ve value int can have is:%d",num);
printf("\nthe largest -ve value int can have is:%d",num1);
}
輸出:最大+ ve值int可以具有:2147483647最大-ve值int可以具有:-2147483648
問題是,即使我采用“ unsigned int”而不是“ int”,結果也是一樣的。
這是因為您將其打印為整數( %d
),而不是無符號整數( %u
)。 另外,您不需要循環即可計算此值-您可以使用limits.h
: UINT_MAX
和INT_MAX / INT_MIN
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.