Multiple choice technology security

With the size of unsigned integers being 4 bytes, What happens when a negative number is entered? unsigned int i; scanf("%u",&i);

  1. A run-time error is encountered and the program aborts

  2. unsigned int variables cannot store the sign (+ or -) of the number. The sign is discarded and only the number is stored in i

  3. A large positive number will be stored in i

  4. Unsigned int variables cannot store signed numbers. Hence in this program i will contain garbage values.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In C, when a negative integer is read into an 'unsigned int' using '%u', the bit pattern of the negative number (in two's complement) is interpreted as a positive value. This results in a very large positive number.