Home > Back-end >  Zhao four old persimmon tong basket again!
Zhao four old persimmon tong basket again!

Time:01-13

A given statement:
 char a []="hello world"; 
int i=0;


God, our dear zhao four old persimmon actually write code like this:
 printf (" 0 02 x "x %, (unsigned char) a [I]); 


Can you believe it! Anyway, we are shocked!!!!!

CodePudding user response:

No problem how

CodePudding user response:


Dear zhao four old persimmon, very not easy to a trip to CSDN, you let me once your short, ah ha ha ha,
The above statement, you write
 printf (" 0 x % 02 x, "a [I]); 

Or written
 printf (" 0 02 x "x %, (unsigned int) a [I]); 

The compiler will thank you, but you write
 printf (" 0 02 x "x %, (unsigned char) a [I]); 

The compiler will think you give it a trouble,
% % x and x requires the corresponding argument as an unsigned int type; Expression a [I] is of type char, its value will be automatically converted into an int to printf. You don't turn the results, you should to turn into a unsigned int instead of unsigned char, because after the switch to unsigned char, the compiler will convert it to an int; Turned a corner, you figure a what to knead? Om, laozhao? Today has been kidding miss zhao, in the hope that zhao old wet don't angry,

CodePudding user response:

I think you made a mistake here
Char conversion directly to the unsigned int
If the sign bit is 1 May fill is 1
Converted to an unsigned char conversion to unsigned int hasn't this problem


Note so I generally don't by dealing with the demand with a type conversion operation is more appropriate

CodePudding user response:

Oh, rectify the
Transition to the unsigned char conversion to int (written in front of the unsigned int mistaken)
Make sure fill is 0
  • Related