C語言無符號變量賦值負數 unsigned char , unsigned short unsigned int unsigned long
Uint及Ulong 賦值后還是負數,Ushort類型和Uchar以下會把負數補碼變正數存儲
另外 pfintf() 打印輸出Uint 變量的內容 ,格式不同,會強制轉換后輸出 。 %d 會把Uint 轉換成int 輸出, %u 會輸出為無符號 。
cout 打印輸出 都是輸出Uint
/**********************實驗1****************************************/
#include "iostream.h"
#include "stdio.h"void main()
{
// unsigned short WuFuHao ;
unsigned long WuFuHao ;
WuFuHao = (-50);
if(WuFuHao == (-50))
{
//cout<<"判斷為真,是-50"<<endl;
//cout << WuFuHao <<endl;
printf("if判斷為真,是-50\n" );
printf("PRINTF打印結果是:%d\n" , WuFuHao);
}
}
打印輸出結果 : if判斷是正確的
if判斷為真,是-50
PRINTF打印結果是:-50
Press any key to continue
/**********************實驗2****************************************/
#include "iostream.h"
#include "stdio.h"void main()
{
unsigned short WuFuHao ;
//unsigned long WuFuHao ;
WuFuHao = (-50);
if(WuFuHao == (-50))
{
//cout<<"判斷為真,是-50"<<endl;
//cout << WuFuHao <<endl;
printf("if判斷為真,是-50\n" );
printf("PRINTF打印結果是:%d\n" , WuFuHao);
}
}
打印輸出結果 : if語句 假
沒有輸出
Press any key to continue
/**********************實驗3****************************************/
#include "iostream.h"
#include "stdio.h"
void main()
{
//unsigned short WuFuHao;
unsigned int WuFuHao ;
WuFuHao = (-10);
cout << WuFuHao <<endl;
printf("PRINTF打印結果是:%d\n" , WuFuHao);
}
輸出結果為:
4294967286
PRINTF打印結果是:-10
Press any key to continue
|