Identify Trap in Signed vs Unsigned Comparison

Code

#include <stdio.h>
#include <stdint.h>

uint8_t signed_unsigned_less(int8_t a, uint8_t b)
{
  if (a<b) return 1;
  else return 0; 
}

int main()
{
    int8_t a;
    uint8_t b;

    scanf("%hhd %hhu", &a, &b);

    printf("%u", signed_unsigned_less(a, b));
    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

-1 1

Expected Output

1