Class | Struct |
---|
Class supports inheritance | Struct does not support inheritance |
Class is having default constructor | Struct does not have default constructor. |
Class is stored in heap as class is a reference type | Struct is stored in stack as struct is a value type |
Garbage collector frees memory in case of class. | Memory in struct is automatically reclaimed. |
While passing a class as a function parameter, the reference of passing variable is copied to the function variable. So if the value of function variable is changed then the value of passing variable will also change. | While passing a struct as a function parameter, the value of passing variable is copied to the function variable. So if the value of function variable is changed then the value of passing variable will not change. |