Activity 01
Pair Programming: Dynamic Array Builder
Pairs start with user input for array size, allocate memory dynamically, fill with values, print contents, then deallocate. They modify to resize the array and compare outputs. Extend by adding error handling for invalid inputs.
How does dynamic memory allocation change the way we manage system resources?
Facilitation TipDuring Pair Programming: Dynamic Array Builder, circulate and ask pairs to verbally explain each allocation and deallocation step before they type it to ensure understanding.
What to look forPresent students with short C++ code snippets involving `new` and `delete`. Ask them to identify potential memory leaks or dangling pointers and explain why. For example: 'int* ptr = new int; delete ptr; ptr = nullptr; // Is this safe?'