1

This is the C program:

int main(void)
{
    unsigned long long int number = 4294967295;
    printf("unsigned long long int size is: %d byte \n", sizeof(unsigned long long int));
    printf("this value is: %d\n", number);
    return 0;
}

this is the output:

unsigned long long int size is: 8 byte
this value is: -1

why output is -1 instead of 4294967295

Johan Jarvi
  • 297
  • 6
  • 13
tkf
  • 27
  • 2
  • 5
    Look up the documentation for printf format strings and check specifically what `%d` means – lurker Jul 12 '21 at 03:58
  • Q: why output is -1 instead of 4294967295? A: because you printed it with `%d`! Unfortunately, different compilers have different "printf" format strings for "unsigned long long": https://stackoverflow.com/questions/2844 – paulsm4 Jul 12 '21 at 04:09

1 Answers1

4

In the printf statement, you have written "%d" which is for int instead of "%llu" which is for unsigned long long int

So for getting the correct output your statement should be

printf("this value is: %llu\n", number);

For more please look at this link below:

https://www.geeksforgeeks.org/data-types-in-c/

Daksharaj kamal
  • 526
  • 1
  • 4
  • 11