From 93fa178d97ed83c3bf53336023a569765e81418e Mon Sep 17 00:00:00 2001 From: Jidong Xiao Date: Fri, 26 Jan 2024 13:40:18 -0500 Subject: [PATCH] adding memory example --- lectures/06_memory/memory.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lectures/06_memory/memory.cpp diff --git a/lectures/06_memory/memory.cpp b/lectures/06_memory/memory.cpp new file mode 100644 index 0000000..6edd544 --- /dev/null +++ b/lectures/06_memory/memory.cpp @@ -0,0 +1,25 @@ +#include + +void func1() { + int a = 42; + std::cout << "a: " << a << std::endl; +} + +void func2() { + int* b = new int(42); + std::cout << "b: " << *b << std::endl; + delete b; +} + +int c = 42; +static int d = 42; + +int main() { + func1(); + func2(); + + std::cout << "c: " << c << std::endl; + std::cout << "d: " << d << std::endl; + + return 0; +}