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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:19:13+00:00 2026-05-14T07:19:13+00:00

If I do the following: int c0 = CHAR_MAX; //8 bit int c1 =

  • 0

If I do the following:

int c0 = CHAR_MAX; //8 bit
int c1 = CHAR_MAX; //8-bit
int i = c0*c1; //store in 32-bit variable
printf("%d\n", i); //prints 16129

We can see that there is no problem with to 8-bit numbers being multiplied together, and producing a 32-bit output.

However, if I do

int i0 = INT_MAX; //32-bit
int i1 = INT_MAX; //32 bit variable
long long int ll = i0*i1; //store in 64-bit variable
printf("%lld\n", ll); //prints 1..overflow!!

In this case, two 32-bit variables were multiplied together, overflowed, and then were assigned to the 64-bit variable.

So why did this overflow happen when multiplying the ints, but not the chars? Is it dependent on the default word-size of my machine? (32-bits)

  • 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-14T07:19:14+00:00Added an answer on May 14, 2026 at 7:19 am

    There’s a logic fault in your explanation of what is going on.

    On at least Linux systems, CHAR_MAX certainly isn’t an 8-bit number. It’s a (more or less) plain preprocessor define, like so:

    #  define SCHAR_MAX     127
    
    /* Maximum value an `unsigned char' can hold.  (Minimum is 0.)  */
    #  define UCHAR_MAX     255
    
    /* Minimum and maximum values a `char' can hold.  */
    #  ifdef __CHAR_UNSIGNED__
    #   define CHAR_MIN     0
    #   define CHAR_MAX     UCHAR_MAX
    #  else
    #   define CHAR_MIN     SCHAR_MIN
    #   define CHAR_MAX     SCHAR_MAX
    #  endif
    

    So, for a system with signed chars, the two last lines are in effect, which means that when you write CHAR_MAX in your code, the compiler sees a plain 127, which has type int.

    This means that the multiplication CHAR_MAX * CHAR_MAX happens at int precision.

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

Sidebar

Related Questions

The following bit of code... void foo(char* x) { int i; int len =
I have the following code. The only problem is that we run it through
I have the following code: int main() { char *sPPhrase[51]; /* Input */ printf(Enter
I have a program structure like following : int firstFunction(unsigned char *firstValue, int s,
I have the following code int ParseData(unsigned char *packet, int len) { struct ethhdr
Why does the following code seg fault before returning: int main() { char iD[20];
I have the following code: int main(int argc, char** argv) { onelog a; std::cout
Given the following table and data. create table prices (productKey int ,PriceType char(10) ,BeginDate
Take the following snippet: 1 #include <stdio.h> 2 #include <stdlib.h> 3 int foo(char [6]);
Today I found the following: #include <stdio.h> int main(){ char x = 255; 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.