Create a `Resource` class that allocates a dynamic integer internally during construction: `data = new int(val);`. Provide a destructor that explicitly runs `delete data;` and prints ‘Cleaned’. Instantiate it in a local scope to trigger the destructor.
A single integer.
Print 'Data: [val]' inside the scope, then 'Cleaned' when destroyed.
Must utilize a destructor to free memory.
10
Data: 10
Cleaned
Classes that manage dynamic resources MUST clean up their own memory in the destructor to prevent leaks when the object falls out of scope.
#include <iostream>
class Resource {
public:
int* data;
// Write your constructor and destructor here
};
int main() {
int val;
if (std::cin >> val) {
{
// Instantiate Resource, print data
}
}
return 0;
}Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used