how much memory it will be allocated in stack as well as in heap when we instantiate the class/struct Student?
I guess id = 4 bytes reference (32 bit machine) and name = 4 bytes reference and facultyAdvisor = 4 bytes reference. So totally 12 bytes in stack and actual size will be in heap. this heap size may vary depends upon the value that we assign to the fields(id, name, facultyAdvisor) that uses object obj(Student obj = new Student())
The same is for struct also right?
public class Student { int id; string name; Professor facultyAdvisor; }
public struct Student { int id; string name; Professor facultyAdvisor; }
Assuming 32 bit CLR (references would be 64 bit on 64 bit CLR) and only taking into account heap allocation for Student
class Student{} class Professor{}
class Student{} struct Professor{}
struct Student{} class Professor{}
struct Student{} struct Professor{}