mirror of
https://github.com/dholerobin/Lecture_Notes.git
synced 2025-07-01 13:06:29 +00:00
Update Pointers_C++.md
This commit is contained in:
parent
3c34bfa2fc
commit
7af44a9ea8
@ -941,7 +941,7 @@ Ex. `int *ptr = new int;`
|
||||
Ex. `int *ptr_arr = new int[10];`
|
||||
Note that length can be any value you provide at run time or compile time.
|
||||
|
||||
The way `new` operator works is that it first checks whether a computer has free memory of the amount requested by a programmer.
|
||||
The way `new` operator works is that it first checks whether a computer has free memory of the amount requested by a programmer.
|
||||
|
||||
If yes, then it will return the address of that available memory. In case that much memory is not available, it will result in `bad_alloc` exception followed by termination of the program.
|
||||
|
||||
@ -1011,6 +1011,8 @@ A memory leak happens when your program loses the address of dynamically allocat
|
||||
|
||||
**Solution:** Delete(deallocate memory) before anything goes wrong.
|
||||
|
||||
|
||||
|
||||
### Dangling pointer
|
||||
|
||||
A pointer that is pointing to a deallocated memory is called a **dangling pointer**. Dereferencing or again deallocating a dangling pointer will lead to undefined behavior(run-time error).
|
||||
|
Loading…
x
Reference in New Issue
Block a user