From the course: Complete Guide to C++ Programming Foundations
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Using objects with pointers - C++ Tutorial
From the course: Complete Guide to C++ Programming Foundations
Using objects with pointers
- [Lecturer] The previous example may have shown you how pointers work, but pointing to existing variables in memory isn't particularly useful. One of the most important applications of pointers is dynamic memory management. When you declare a regular variable, you are statically allocating memory for it. The compiler already knows that space in memory will be needed. However, most real applications create variables and objects in memory on the fly during runtime. This is known as dynamic memory management, and it happens in the heap. In C, it is common to dynamically allocate memory using the malloc family of functions, which is short for memory allocation. You as a programmer are responsible of freeing up the memory you allocated in runtime to avoid memory leakage, but this is where C++ plus really shines. The use of pointers is supported by the language to dynamically allocate memory for new objects when calling the class constructor and also to free their memory when you no longer…
Contents
-
-
-
-
-
-
(Locked)
Arrays7m 27s
-
Pointers7m 59s
-
(Locked)
How arrays and pointers are related5m 14s
-
(Locked)
Using objects with pointers10m 56s
-
(Locked)
The vector class5m
-
(Locked)
Using objects with vectors6m 29s
-
(Locked)
References4m 56s
-
(Locked)
C strings11m 16s
-
(Locked)
The string class4m 14s
-
(Locked)
Solution: Vector manipulation2m
-
(Locked)
-
-
-
-
-
-