Difference between Int32 and UInt32 in C#

Int32: This Struct is used to represents 32-bit signed integer. The Int32 can store both types of values including negative and positive between the ranges of -2147483648 to +2147483647.

Example :

C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to show the
// difference between Int32
// and UInt32
  
using System;
using System.Text;
  
public
class GFG {
  
  // Main Method
  static void Main(string[] args) {
  
    // printing minimum & maximum values
    Console.WriteLine("Minimum value of Int32: " 
                      + Int32.MinValue);
    Console.WriteLine("Maximum value of Int32: " 
                      + Int32.MaxValue);
    Console.WriteLine();
  
    // Int32 array
    Int32[] arr1 = {-3, 0, 1, 3, 7};
  
    foreach (Int32 i in arr1)
    
      Console.WriteLine(i);
    }
  }
}

chevron_right


Output:

Minimum value of Int32: -2147483648
Maximum value of Int32: 2147483647

-3
0
1
3
7

UInt32: This Struct is used to represents 32-bit unsigned integer. The UInt32 can store only positive value only which ranges from 0 to 4294967295.

Example :



C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to show the 
// difference between Int32 
// and UInt32
  
using System;
using System.Text;
  
public class GFG{
      
    // Main Method
    static void Main(string[] args)
    {
  
        // printing minimum & maximum values
        Console.WriteLine("Minimum value of UInt32: "
                          + UInt32.MinValue);
        Console.WriteLine("Maximum value of UInt32: "
                          + UInt32.MaxValue);
        Console.WriteLine();
          
        // Int32 array
        UInt32[] arr1 = { 13, 0, 1, 3, 7};
          
        foreach (UInt32 i in arr1)
        {
            Console.WriteLine(i);
        }
    }
}

chevron_right


Output:

Minimum value of UInt32: 0
Maximum value of UInt32: 4294967295

13
0
1
3
7

Differences between Int32 and UInt32 in C#

Sr.No

INT32

UINT32

1.

Int32 is used to represents 32-bit signed integers . UInt32 is used to represent 32-bit unsigned integers.

2.

Int32 stands for signed integer. UInt32 stands for unsigned integer.

3.

It can store negative and positive integers. It can store only positive integers.

4.

It takes 4-bytes  space in the memory. It also takes 4-bytes space in the memory.

5.

The range of Int32 is from -2147483648 to +2147483647. The UInt32 ranges from 0 to 4294967295.

 6.

 Syntax to declare the Int32 :

Int32 variable_name;

  Syntax to declare the UInt32:

UInt32 variable_name;



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.