-1

I was trying to figure out the minimum and maximum value for an unsigned data type. I know that the minimum unsigned value is 0 and the maximum value is (2^n)-1. However, when I tried to run my program (I cannot post my code, but you can refer to this), I keep getting -1 as the maximum value. Can someone explain to me why? Also, UINT_MAX is giving me 4294967295 while ULLONG_MAX is 4294967295. However, the maximum value of unsigned int is supposed to be 65535 while unsigned long long int is supposed to be +18,446,744,073,709,551,615.Why is it the output is different?

eLg
  • 479
  • 3
  • 11
  • 24

1 Answers1

6

Whats the format specifier are you using to print those values ? These kind of error mostly occur due to wrong format specifier.

#include <stdio.h>
#include <limits.h>

int main()
{  
    printf("%u", UINT_MAX); // This will print 4294967295 (system dependent)
    printf("%d", UINT_MAX); // This will print -1
    return 0;
}
sameer chaudhari
  • 688
  • 6
  • 14