Why, what, creating an array, value type vs reference type

Notes:

Why do we need arrays? : [Starts at: 03min:30sec]
What is an array? : [Starts at: 06min:20sec]
Difference between value types and reference types? : [Starts at: 07min:10sec]
Declaring or creating an array : [Starts at: 11min:45sec]
Memory representation of an array : [Starts at: 15min:37sec]

Why do we need arrays? : [Starts at: 03min:30sec]

Example Code:

using UnityEngine;
public class ArraysDemo : MonoBehaviour
{
void Start ()
{
// Declaring 5 variables
int num1, num2, num3, num4, num5;

// Initializing 5 variables
num1 = 10;
num2 = 20;
num3 = 30;
num4 = 40;
num5 = 50;

// Displaying 5 variables
Debug.Log (num1);
Debug.Log (num2);
Debug.Log (num3);
Debug.Log (num4);
Debug.Log (num5);
}
}

Problem:
if we need to create 100 or more variables, initialize and display them,
then
It takes a lot of time
It increases file size
It is difficult to manage the code

Solution:
Array

What is an array? : [Starts at: 06min:20sec]

Array : is a collection of homogeneous (same) type of data elements
Arrays are of reference types
Arrays are indexed variables

Difference between value types and reference types? : [Starts at: 07min:10sec]

Value type:
Value type variables hold the actual value
Ex:
int, float etc.
Default value of number types is 0

Reference type:
Reference type variables hold the address of another memory location
Reference type variables are implicit pointers
Ex: string
Anything is of object type is considered as reference type
Default value of a reference type is null
null means nowhere the reference variable is pointing

Example Code:

using UnityEngine;
public class ArraysDemo : MonoBehaviour
{
void Start ()
{
// value type
int num = 10;
Debug.Log (num);

// reference type
string name = "Unity";
Debug.Log (name);
}
}

Creating an array : [Starts at: 11min:45sec]

Syntax: Declaring & initializing an array variable
dataype[] arrayName = new datatype[size];
ex:
int[] numbers = new int[5];
where:
int[] numbers: numbers is an array variable of type int
new: new keyword creates memory locations on the heap
and returns the base address

Memory representation of an array : [Starts at: 15min:37sec]

1. System creates some memory for Start() in the stack
and creates its local variables
2. new keyword creates memory locations on the heap
3. After the Start() execution, garbage collector collects
all the memory locations allocated for reference variables of that function
4. System deallocates the memory created for Start()

Note:
Stack:
is a limited memory partition
meant to manage function calls
Heap :
is an unlimited memory partition
meant to create and delete memory locations dynamically

Note:
As c# has garbage collector,
it is a memory managed (i.e.managed) programming language.

As C++ has no garbage collector,
it is unmanaged programming language.
It is programmers responsiblity to manage the memory.
By saying at the end of function
// delete memory locations allocated for numbers reference from the heap
delete[] numbers;
// remove the pointer by setting it to null
numbers=null;