Definition1: Variable is an identity given to memory location.
Definition2: Variable is a named memory location
Syntax: datatype identity = value; Examples: String name = "Amar"; int age = 23; char gender = 'M'; bool married = false; double salary = 35000.00;
Declaration, Assignment, Update and Initialization of Variable:
- Declaration: creating a variable without any value.
- int a ;
- Assignment: Storing a value into variable which is already declared.
- a = 10 ;
- Modify: Increase or Decrease the value of variable.
- a = a + 5 ;
- Initialization: Assigning value at the time of declaration
- int b = 20 ;
- Identifier is a name given to class, method, variable etc.
- Identifier must be unique
- Identifier is used to access the member.
Rules to create identifier:
- Identifier allows [A-Z] or [a-z] or [0-9], and underscore(_).
- Spaces not allowed in identifier.
- Identifier should not start with digit.
- Identifier can starts with special symbol.
- We can’t use the C# .Net reserved keywords as an identifier.