Displacement implicit type conversion pee

Source: Internet
Author: User

Example one:

int main ()

{

unsigned char a = 0XA5;

unsigned char b = ~a >> 1+2+3;

printf ("B =%d\n", b);

}

What is the value of Q B?

Here B = 253;

The teacher said that the first shift to take the reverse, said to take the reverse is the same as the right to the back of the operation (I novice do not understand, ~ The operational level is not higher):

1010 0101 >> 6 0000 0010 Reverse 1111 1101 (253)

Small m look at the assembly code and the result is this

1010 0101 extended to 16 bits (register 16 bits)

0000 0000 1010 0101 Reverse Priority 1111 1111 0101 1010

Re-displacement of 0000 0011 1111 1101 given b to intercept the first 8 digits 1111 1101 (253)

If A is char a = 0xa5 The value of the last B is 1

According to the teacher said ~ post-op

1010 0101 >> 6 1111 1110 reverse 0000 0001 (1)

Expand by the idea of small m (implicit conversion)

1111 1111 1010 0101 First take reverse 0000 0000 0101 1010

re-displacement 0000 0000 0000 0001 (1) also 1

is not sure that that is right or is right, I hope to have a senior to mention a bit.

Example two:

int main ()

{

Char *a = "China";

Char *b = "American;

if (strlen (a)-strlen (b) > 0)

{

printf ("china\n");

}

Else

{

printf ("american\n");

}

}

The result output is China;

Here strlen returns the unsigned type, and an implicit conversion will occur so > left is always greater than or equal to 0

Small m Summary: All data is implicitly converted until the operation is started, until a conversion is made to the assignment

The symbol is converted to unsigned, and the shape is converted to floating point.

Small m is also very vegetable. If there is any mistake, I hope that the elder ancestors WA

Displacement implicit type conversion pee

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.