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 7583431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:40:34+00:00 2026-05-30T18:40:34+00:00

In the following code: #include stdio.h signed char a= 0x80; unsigned char b= 0x01;

  • 0

In the following code:

#include "stdio.h"
signed char a= 0x80;
unsigned char b= 0x01;


void main (void)
{
    if(b*a>1)
        printf("promoted\n");
    else if (b*a<1)
        printf("why doesnt promotion work?");

    while(1);
}

I expected “promoted’ to be printed. But it doesnt. Why?
If I can the datatypes to signed and unsigned int, and have a as a negative number, eg, 0x80000000 and b as a positive number, 0x01, “promoted” gets printed as expected.

PLZ HELP me understand what the problem is!

  • 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-30T18:40:35+00:00Added an answer on May 30, 2026 at 6:40 pm

    You’ve just been caught by the messy type-promotion rules of C.

    In C, intermediates of integral type smaller than int are automatically promoted to int.

    So you have:

    0x80 * 0x01 = -128 * 1
    

    0x80 gets signed extended to type int:

    0xffffff80 * 0x00000001 = -128 * 1 = -128
    

    So the result is -128 and thus is less than 1.


    When you use type int and unsigned int, both operands get promoted to unsigned int. 0x80000000 * 0x01 = 0x80000000 as an unsigned integer is bigger than 1.


    So here’s the side-by-side comparison of the type promotion that’s taking place:

    (signed char) * (unsigned char) -> int
    (signed int ) * (unsigned int ) -> unsigned int
    
    (signed char)0x80       * (unsigned char)0x01 -> (int)         0xffffff80
    (signed int )0x80000000 * (unsigned int )0x01 -> (unsigned int)0x80000000
    
    (int)         0xffffff80 is negative   ->   prints "why doesnt promotion work?"
    (unsigned int)0x80000000 is positive   ->   prints "promoted"
    

    Here’s a reference to the type-promotion rules of C.

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

Sidebar

Related Questions

Consider the following code: #include <stdio.h> int main (void) { char str1[128], str2[128], str3[128];
Consider the following code: #include <stdio.h> int main(void) { int a[10]; printf(%d,(int)sizeof(a)); //prints 10*sizeof(int)
Test the following code: #include <stdio.h> #include <stdlib.h> main() { const char *yytext=0; const
i have the following code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =
Consider the following code: #include <stdio.h> #include <ctype.h> char* Mstrupr(char* szCad); int main() {
I executed the following code #include <stdio.h> int main() { printf(%f\n, 9/5); } Output
I have the following code: #include <stdlib.h> #include <stdio.h> #include <errno.h> void main(void) {
We have the following code: #include <stdio.h> #define LEN 10 int main(void) { int
I had the following code : #include<stdio.h> void main() { int * a; int
When I run the following code: #include <stdio.h> int main(int argc, char *argv[]) {

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.