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:
using System;
using System.Text;
class geeks {
static void Main( string [] args)
{
int num = -245;
Console.WriteLine( "num: " + num);
Console.WriteLine( "Size of a int variable: " + sizeof ( int ));
}
}
|
Output:
num: -245
Size of a int variable: 4
Example 2:
using System;
using System.Text;
namespace Test {
class geeks {
static void Main( string [] args)
{
int num = 7923645;
Console.WriteLine( "Type of num: " + num.GetType());
Console.WriteLine( "num: " + num);
Console.WriteLine( "Size of a int variable: " + sizeof ( int ));
Console.WriteLine( "Min value of int: " + int .MinValue);
Console.WriteLine( "Max value of int: " + int .MaxValue);
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:
using System;
using System.Text;
class geeks {
static void Main( string [] args)
{
int num1 = 2147483650;
Console.WriteLine( "num1: " + num1);
int num = 792.53;
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’
Last Updated :
22 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...