Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why minimum possible integer minus one becomes maximum possible integer in c

I know that c works in two’s complement but still i can’t undrstand how the program below gives me 2147483647 as output.

#include<stdio.h>
int main(){

int a=-2147483648;
a-=1;
printf("%d",a);

}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

minimum number in twos comlement is 100000…0
if you reduce one from that it means computer will add -1 to it
-1 in twos complement is: 11111…1
so if you add them the answer is 0111111…1
which is maximum integer or 2147483647

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading