Solution for Exercise 6-6

ex0606

#include <stdio.h>

int main()
{
    unsigned int ono;

    ono = -10;
    printf("The value of ono is %u.\n",ono);
    return(0);
}

Output

The value of ono is 4294967286.

Notes

* The - (negative) unary operator assigns the value negative ten to the variable ono in Line 7. I recognize that you probably just accept -10 as a value, but it's really the value 10 with the - (negative) unary operator prefixed.

* If you change the %u placeholder to %d in Line 8, the result displayed is -10. As with floating point numbers and precision, the value -10 is stored only one way inside the computer. It can be output as an unsigned value, 4294967286, or it can be displayed as a signed value, -10. The difference depends on the conversion character used.

* Remember, even though the conversion character controls the output, some functions require or return unsigned int values. When you don't specify an unsigned int variable to hold the value, the compiler complains.