Having a basic understanding of the two types of program memory will help you better understand how to create variables dynamically. This video will help you to understand what stack and heap memory are.
Now that you understand memory basics and how pointers work, there are two operators that you'll need to know.
Review Questions
The following are examples of questions similar to what you can expect to see on the next exam.
Consider the following code:
struct Student
{
int ID;
string Name;
};
- How would you create an instance of a student (on the stack)? Student s;
- How would you create an instance of a student (on the heap)? Student *pS = new Student;
- If s is a Student instance, how would you set the Name? s.Name = "Bill";
- If pS is a pointer to a Student, how would you set the Name? pS->Name = "Bill";