Analyze the following code…
‘int i’ is declared as unsigned but the compiler does not give error and gives output as -121 (Range of unsigned int is positive.)
Please suggest the reason.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
unsigned int i=-121;
printf("%d",i);
getch();
}
As far as I know, the %d is used for signed int values, and now if you want to use it with unsigned value, you cannot use %d as it will display the signed integer value stored at that memory location. Try %u. It should work.