Reputation: 421
I have a very basic question. Lets say I have two variables(uint16_t a, uint16_t b) and in memory they are aligned next to each other like a=> 0x0 => 0x15 and b=> 0x16 to 0x31
Lets assume a = 0, b = 65535,
(1) if i increment b(b++), b will become 0 but will it affect 'a' 0th bit?
(2) if i right shift b( b = b << 1), will it affect 'a' ?
Thank you
Upvotes: 1
Views: 156
Reputation: 1
No, a correctly designed system will not have that happen. Also, I will point out that your numeral notation is incorrect by common convention. 0x is generally used to notate hexadecimal numbers, including in the C language, but from the context of your question, you are prefixing decimal base numbers with it for no apparent reason. For example, 0x31 is equal to 49 in decimal. And 16+16 is not equal to 49.
Upvotes: 0
Reputation: 4663
a
and b
is a uint16_t
, so it is of an unsigned type. And unsigned overflow (or wrap-around) is well-defined in C. It won't change the memory besides it.
Upvotes: 0