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:
// 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)); } } |
Output:
num: -245 Size of a int variable: 4
Example 2:
// 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(); } } } |
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:
// 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); } } |
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’
Recommended Posts:
- How to implement is functionality without using is keyword in C#
- C# | this Keyword
- C# | finally keyword
- C# | as Operator Keyword
- C# | is Operator Keyword
- Is vs As operator keyword in C#
- Static keyword in C#
- typeof Operator Keyword in C#
- Invoking an overloaded constructor using this keyword in C#
- Difference between readonly and const keyword in C#
- LINQ | Let Keyword
- uint keyword in C#
- byte Keyword in C#
- decimal keyword in C#
- char keyword in C#
- bool Keyword in C#
- sbyte Keyword in C#
- float keyword in C#
- double Keyword in C#
- void Keyword in C#
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.

