Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6081921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:13:51+00:00 2026-05-23T11:13:51+00:00

main() { unsigned x = 1; char y = -1; if (x > y)

  • 0
main() {
    unsigned x = 1;
    char y = -1;

    if (x > y)
        printf("x>y");
    else
        printf("x<=y");
}

I expected x>y,
but I had to change unsigned int to signed int to get the expected result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:13:51+00:00Added an answer on May 23, 2026 at 11:13 am

    If char is equivalent to signed char:

    • char is promoted to int (Integer Promotions, ISO C99 §6.3.1.1 ¶2)
    • Since int and unsigned int have the same rank, int is converted to unsigned int (Arithmetic Conversions, ISO C99 §6.3.1.8)

    If char is equivalent to unsigned char:

    • char may be promoted to either int or unsigned int:
      • If int can represent all unsigned char values (typically because sizeof(int) > sizeof(char)), char is converted to int.
      • Otherwise (typically because sizeof(char)==sizeof(int)), char is converted to unsigned.
    • Now we have one operand that is either int or unsigned int, and another that is unsigned int. The first operand is converted to unsigned int.

    Integer promotions:
    An expression of a type of lower rank that int is converted to int if int can hold all of the values of the original type, to unsigned int otherwise.

    Arithmetic conversions:
    Try to convert to the larger type. When there is conflict between signed and unsigned, if the larger (including the case where the two types have the same rank) type is unsigned, go with unsigned. Otherwise, go with signed only in the case it can represent all the values of both types.

    Conversions to integer types(ISO C99 §6.3.1.3):

    Conversion of an out-of-range value to an unsigned integer type is done via wrap-around (modular arithmetic).

    Conversion of an out-of-range value to a signed integer type is implementation defined, and can raise a signal (such as SIGFPE).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is one program #include<stdio.h> #include<stdlib.h> int main() { unsigned char a=0x80; printf(%d\n,a<<1); }
How does one explain: int main() { unsigned char z=-1; printf(%u %d,z,z); } gives
main() { if ( -1 < (unsigned char) 1 ) printf(less than); else printf(NOT
I want to know how malloc and free work. int main() { unsigned char
#include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char
#include<stdio.h> #include<string.h> int main() { unsigned char *s; unsigned char a[30]=Hello world welcome; memcpy(s,&a,15);
#include < stdio.h > #include < string.h > int main() { unsigned char a;
#include <stdio.h> int main() { unsigned char data[1]; FILE *f = fopen(bill.jpg, rb); while
Why is this code throwing up a SIGSEGV : int main() { unsigned long
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.