int Keyword in C#

Keywords are the words in a language that are used for some internal process or represent some predefined actions. int is a keyword that is used to declare a variable which can store an integral type of value (signed integer) the range from -2,147,483,648 to 2,147,483,647. It is an alias of System.Int32.

Syntax:

int variable_name = value;

Int keyword occupies 4 bytes (32 bits) space in the memory.

Example:

Input: num: -245

Output: num: -245
        Size of an int variable: 4

Input: num = 7923645

Output: Type of num: System.Int32
        num: 7923645
        Size of a int variable: 4

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for int keyword
using System;
using System.Text;
  
class geeks {
  
    static void Main(string[] args)
    {
        // variable declaration
        int num = -245;
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size
        Console.WriteLine("Size of a int variable: " + sizeof(int));
    }
}

chevron_right


Output:

num: -245
Size of a int variable: 4

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for int keyword
using System;
using System.Text;
  
namespace Test {
  
class geeks {
  
    static void Main(string[] args)
    {
        // variable declaration
        int num = 7923645;
  
        // to print type of variable
        Console.WriteLine("Type of num: " + num.GetType());
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size
        Console.WriteLine("Size of a int variable: " + sizeof(int));
  
        // to print minimum & maximum value of int
        Console.WriteLine("Min value of int: " + int.MinValue);
        Console.WriteLine("Max value of int: " + int.MaxValue);
  
        // hit ENTER to exit
        Console.ReadLine();
    }
}
}

chevron_right


Output:

Type of num: System.Int32
num: 7923645
Size of a int variable: 4
Min value of int: -2147483648
Max value of int: 2147483647

Example 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for int keyword
using System;
using System.Text;
  
class geeks {
  
    static void Main(string[] args)
    {
  
        // variable declaration
        int num1 = 2147483650;
  
        // to print value
        Console.WriteLine("num1: " + num1);
  
        // variable declaration
        int num = 792.53;
  
        // to print value
        Console.WriteLine("num: " + num);
    }
}

chevron_right


Error: When we input wrong integer and also input number beyond the range

Constant value `2147483650′ cannot be converted to a `int’
Cannot implicitly convert type `double’ to `int’




My Personal Notes arrow_drop_up


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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.