ProAnswers.org

what will happen if I assign negative value to unsigned int?

unsigned int a;
a = -1;

this is not giving any compilation error but there is warning.

1 Like

negative value will be considered as a positive and then assigned to it.

example:
int val = -512
unsigned int uVal = val

uVal = 0xFFFFFE00; // 4294966784 in decimal