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

  • Home
  • SEARCH
  • 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 965857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:03:57+00:00 2026-05-16T02:03:57+00:00

#include <stdio.h> int main() { unsigned char i=0x80; printf(%d,i<<1); return 0; } Why does

  • 0
#include <stdio.h>
int main()
{
    unsigned char i=0x80;
    printf("%d",i<<1);
    return 0;
}

Why does this program print 256?

As I understand this, since 0x80= 0b10000000, and unsigned char has 8 bits, the ‘1’ should overflow after left shift and the output should be 0, not 256.

  • 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-16T02:03:58+00:00Added an answer on May 16, 2026 at 2:03 am

    This is a result of C’s integer promotion rules. Essentially, most any variable going into an expression is “promoted” so that operations like this do not lose precision. Then, it’s passed as an int into printf, according to C’s variable arguments rules.

    If you’d want what you’re looking for, you’d have to cast back to unsigned char:

    #include <stdio.h>
    int main()
    {
        unsigned char i=0x80;
        printf("%d",((unsigned char)(i<<1)));
        return 0;
    }
    

    Note: using %c as specified in Stephen’s comment won’t work because %c expects an integer too.

    EDIT: Alternately, you could do this:

    #include <stdio.h>
    int main()
    {
        unsigned char i=0x80;
        unsigned char res = i<<1;
        printf("%d",res);
        return 0;
    }
    

    or

    #include <stdio.h>
    int main()
    {
        unsigned char i=0x80;
        printf("%d",(i<<1) & 0xFF);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 496k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Suppose you have a solution a such that f(a) =… May 16, 2026 at 11:42 am
  • Editorial Team
    Editorial Team added an answer ActionScript must be using a different string encoding, but it… May 16, 2026 at 11:42 am
  • Editorial Team
    Editorial Team added an answer Try this: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"… May 16, 2026 at 11:42 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

#include <stdio.h> int main(void){ unsigned a[3][4] = { {2,23,6,7}, {8,5,1,4}, {12,15,3,9} }; printf(%u,*((int*)(((char*)a)+4))); return
#include<stdio.h> int main() { unsigned char c; c = 300; printf(%d,c); return 0; }
#include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char
this program hangs after taking first argument:- #include <stdio.h> #include <conio.h> void ellip(char*,...); int
#include vss.h #include vswriter.h #include <VsBackup.h> #include <stdio.h> #define CHECK_PRINT(result) printf(%s\n,result==S_OK?S_OK:error) int main(int argc,
can any one give me the dry output for this program? #include <stdio.h> main()
#include <stdio.h> #define MAX 5 int stk[MAX]; int top=-1; main() { char ch; void
I've just typed in an example from K&R... #include <stdio.h> int main (int argc,
I have this bit of code that is outputting the wrong results. #include <stdio.h>
Given the following snippet: #include <stdio.h> typedef signed long long int64; typedef signed int

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.