Integral type overflow

The integral type may overflow.

The following example shows that the overflow happens when subtracting one from minimum int value.


using System;

class Program
{
    static void Main(string[] args)
    {
        int i = int.MinValue;
        
        int result = i-1;
        Console.WriteLine("i=" + i);

        Console.WriteLine("result="+result);
        Console.WriteLine("result is int.MaxValue:" + (result == int.MaxValue));


    }
}

The output:


i=-2147483648
result=2147483647
result is int.MaxValue:True
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.