Keywords are the words in a language that are used for some internal process or represent some predefined actions. long is a keyword that is used to declare a variable which can store a signed integer value from the range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. It is an alias of System.Int64.
Syntax:
long variable_name = value;
long keyword occupies 8 bytes (64 bits) space in the memory.
Example:
Input: num: 34638
Output: num: 34638
Size of a long variable: 8
Input: num = -79349367648374345
Output: Type of num: System.Int64
num: -79349367648374345
Size of a long variable: 8
If we input number beyond the range, it shows error-
Integral constant is too large
Example 1:
using System;
using System.Text;
class GFG {
static void Main( string [] args)
{
long num = 34638;
Console.WriteLine( "num: " + num);
Console.WriteLine( "Size of a long variable: " + sizeof ( long ));
}
}
|
Output:
num: 34638
Size of a long variable: 8
Example 2:
using System;
using System.Text;
namespace Test {
class GFG {
static void Main( string [] args)
{
long num = -79349367648374345;
Console.WriteLine( "Type of num: " + num.GetType());
Console.WriteLine( "num: " + num);
Console.WriteLine( "Size of a long variable: " + sizeof ( long ));
Console.WriteLine( "Min value of long: " + long .MinValue);
Console.WriteLine( "Max value of long: " + long .MaxValue);
Console.ReadLine();
}
}
}
|
Output:
Type of num: System.Int64
num: -79349367648374345
Size of a long variable: 8
Min value of long: -9223372036854775808
Max value of long: 9223372036854775807
Last Updated :
22 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...