What number does each line of code print out Briefly explain

What number does each line of code print out? Briefly explain why.

printf(\"%u\ \",(unsigned char)(-2));
printf(\"%d\ \",(unsigned char)(-2));
  
printf(\"%u\ \",(uint16_t)(-2));
printf(\"%d\ \",(uint16_t)(-2));
  
printf(\"%u\ \",(unsigned int)(-2));
printf(\"%d\ \",(unsigned int)(-2));

Solution

printf(\"%u\ \",(unsigned char)(-2));
unsigned char value of -2 converted to unsigned int is 254

printf(\"%d\ \",(unsigned char)(-2));
unsigned char value of -2 converted to int is 254

printf(\"%u\ \",(uint16_t)(-2));
uint16_t is unsigned 16-bit integer
unsigned 16-bit of -2 converted to unsigned int is 65534

printf(\"%d\ \",(uint16_t)(-2));
unsigned 16-bit of -2 converted to int is 65534

printf(\"%u\ \",(unsigned int)(-2));
unsigned int value of -2 converted to unsigned gives memory address 4294967294

printf(\"%d\ \",(unsigned int)(-2));
unsigned char value of -2 converted to int is -2

What number does each line of code print out? Briefly explain why. printf(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site