Data type:
- In the declaration of every variable, it is mandatory to specify its data type.
- Data type describes,
- The size of memory allocated to variable.
- The type of data allowed to store into variable.
Syntax:
- data_type variable_name = value ;
Example:
- int sum = 0;
- float balance = 3000.0;
- String name = “Amar”;
Data types classified into Primitive and Non-Primitive types.
Data Types | Memory Size | Range |
char | 1 byte | -128 to 127 |
short | 2 byte | -32,768 to 32,767 |
int | 4 byte | -2,147,483,648 to -2,147,483,647 |
long | 8 byte | ?9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
float | 4 byte | 1.5 * 10-45 – 3.4 * 1038, 7-digit precision |
double | 8 byte | 5.0 * 10-324 – 1.7 * 10308, 15-digit precision |
Character data type: Character type variable is used to store alphabets, digits and symbols.
using System;
public class Program
{
public static void Main()
{
char x = 'A';
char y = '5';
char z = '$';
Console.WriteLine("x val : " + x + "\ny val : " + y + "\nz val : " + z);
}
}
ASCII : Representation of each character of language using constant integer value.
A-65 B-66 … … … Z-90 | a-97 b-98 …. …. …. z-122 | 0-48 1-49 .. .. .. 9-57 | *-34 #-35 $-36 … … … |