Promotion and assignment

  • Thread starter Tomás Ó hÉilidhe
  • Start date
T

Tomás Ó hÉilidhe

Take the following:

char unsigned i = 0, j = 5;
...
...
i &= j;

I'd like to see what happens in the last statement. If it were
identical to:

i = i & j;

then the follwoing would happen:
* On the right-hand side, both i and j would be promoted to either
signed int or unsigned int
* The bitwise AND would be performed on these two int's
* Then the result would be converted to an unsigned char to be stored
in i

Does exactly the same thing happen with i &= j?
 
V

vippstar

Take the following:

char unsigned i = 0, j = 5;
...
...
i &= j;

I'd like to see what happens in the last statement. If it were
identical to:

i = i & j;

then the follwoing would happen:
* On the right-hand side, both i and j would be promoted to either
signed int or unsigned int
Don't you mean int unsigned? :)
* The bitwise AND would be performed on these two int's
* Then the result would be converted to an unsigned char to be stored
in i

Does exactly the same thing happen with i &= j?
Yes, for the long answer see Mr Sosmans post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top