'How is a negative character stored in memory? [duplicate]

#include <stdio.h>
int main()
{
    int i = 23;
    char c = -23;
    if (i < c)
        printf("Yes\n");
    else
        printf("No\n");
}

This segment of code executes the else block, but it executes the if block if we replace integer value with unsigned int i = 23. Printing these values with %x results in

  1. c=ffffffe9
  2. i=17

My question here is how unsigned ints and char variables gets stored in memory?

c


Solution 1:[1]

This should help you understand it a bit better: Signed to unsigned conversion in C - is it always safe?

"The int data type is signed and has a minimum range of at least -32767 through 32767 inclusive. The actual values are given in limits.h as INT_MIN and INT_MAX respectively.

An unsigned int has a minimal range of 0 through 65535 inclusive with the actual maximum value being UINT_MAX from that same header file."

Enjoy! :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Grue