Solution for Exercise 6-7
ex0607
#include <stdio.h> int main() { unsigned int ono; ono = -10; printf("The value of ono is %u.\n",ono); return(0); }
Notes
* The -
unary operator is used to assign the value negative ten to the variable ono. 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 displayed as an unsigned value, 4294967286, or it can be displayed as a signed value, -10. The display depends on the conversion character used.
* Remember, even though the conversion character controls the display, some functions require or return unsigned int values. When you don't specify an unsigned int value, the compiler complains.
Copyright © 1997-2024 by QPBC.
All rights reserved