A student of one of my courses asked me why addresses are sometimes shown as negative values when they are displayed as decimal integers in C. The answer is not obvious. It turns out that this is a side-effect of assigning very large numbers and it can cause unexpected results in all kinds of odd places that have nothing at all to do with addresses. And it doesnāt only affect C programs either.
In this video, I go riding the ranges to track down the mystery of unexpected negative numbers.
PROGRAMMING BOOKS
====================
If you want to learn programming in more depth (and also support this channel!) you might think of buying one of my books. I have written books on C programming, Using Pointers in C, Recursion and other programming topics. You can buy my books (paperback or Kindle) on Amazon.
āCODE WITH HUWā ON TWITTER:
=================================
twitter.com/codewithhuw āCODE WITH HUWā ON FACEBOOK:
=================================
www.facebook.com/CodeWithHuw Good luck! And good programming!
@NikolaNevenov86
1 year ago
could this be linked to how ints are represented in bits? Like a number that is 0111 is incremented by 1 it will become 1000. In signed ints the last bit is set as the + or - sign. So the number 7(0111) will become -8(1000) if we follow the two complement rule and any addition to (1000) will start decreasing the number like 1001 is -7.
|