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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:22:42+00:00 2026-05-13T16:22:42+00:00

Consider this int i = 2147483647; var n = i + 3; i =

  • 0

Consider this

        int i = 2147483647;
        var n = i + 3;
        i = n;

        Console.WriteLine(i);           // prints -2147483646    (1)
        Console.WriteLine(n);           // prints -2147483646    (2)
        Console.WriteLine(n.GetType()); // prints System.Int32   (3)

I am confused with following

  • (1) how could int hold the value -2147483646 ? (int range = -2,147,483,648 to 2,147,483,647)
  • (2) why does this print -2147483648 but not 2147483648 (compiler should
    decide better type as int range
    exceeds)
  • (3) if it is converted somewhere, why n.GetType() gives System.Int32
    ?

Edit1: Made the correction: Now you will get What I am Getting. (sorry for that)

var n = i + 1; to

var n = i + 3;

Edit2: One more thing, if it as overflow, why is an exception not raised ?

Addition: as the overflow occurs, is it not right to set the type for

var n

in statement var n = i + 3; to another type accordingly ?


you are welcome to suggest a better title, as this is not making sense to…. me at least

Thanks

  • 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-13T16:22:42+00:00Added an answer on May 13, 2026 at 4:22 pm

    Update: Poster fixed his question.

    1) This is output is expected because you added 3 to int.MaxValue causing an overflow. In .NET by default this is a legal operation in unchecked code giving a wrap-around to negative values, but if you add a checked block around the code it will throw an OverflowException instead.

    2) The type of a variable declared with var is determined at compile time not runtime. It’s a rule that adding two Int32s gives an Int32, not a UInt32, an Int64 or something else. So even though at runtime you can see that the result is too big for an Int32, it still has to return an Int32.

    3) It’s not converted to another type.

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

Sidebar

Related Questions

Consider this code: template <int N> struct X { friend void f(X *) {}
Consider this interesting set of types: class A { public virtual int MyProperty {
Consider this pointless program: /* main.c */ #include <stdlib.h> #include <unistd.h> int main(int argc,
Consider this: var propertyinfo = typeof(Customer).GetProperty(sortExpressionStr); Type orderType = propertyinfo.PropertyType; now I want to
consider this piece of code: Welcome to Scala version 2.8.0.r0-b20100714201327 (Java HotSpot(TM) 64-Bit Server
Consider this scenario we have a class A which is singleton it has a
Consider this example The Interface interface IBusinessRules { string Perform(); } The Inheritors class
Possible Duplicate: Is there a printf converter to print in binary format? Consider this
As background, I gave an answer to this post a little while ago: Return
I am a little confused about how can I read each argument from the

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.