Bifalgorithm post

What is the null pointer in C++? A null pointer is a kind of pointer that does not currently points to any memory location. In previous version of C++, a null pointer was initialized with null. But in the modern C++, we use the null PTR to represent or initialize a null pointer. Like here, PTR is a null pointer. Now if we try to de-reference a null pointer, then it will result in an undefined behavior. Null pointer are commonly used to initialize a pointer. It can be used with the conditions to check if pointer is a null pointer or not. This is a practical example. In this line we have created a memory on the heap and the PTR pointer is pointing into it. Then we deleted the memory from the heap. At this point, pointer PTR becomes a dangling pointer. Then we assigned inl_ptr to this PTR and this line will make PTR inl_pointer. We can safely delete inl_pointer. It will not result in any undefined behavior.

What is the null pointer in C++? A null pointer is a kind of pointer that does not currently points to any memory location. In previous version of C++, a null…

Ideas in this flowchart

  • Null Pointer in C++
  • Definition
  • Does not point to memory
  • Initialization
  • Previous C++ versions
  • Initialized with null
  • Modern C++
  • Use nullptr
  • Dereferencing
  • Undefined behavior
  • Common Usage
  • Initialize a pointer
  • Conditional checks
  • Practical Example
  • Memory allocation on heap
  • PTR points to memory
  • Memory deletion
  • PTR becomes dangling pointer
  • Assign nullptr to PTR
  • PTR becomes nullptr
  • Safe deletion
  • No undefined behavior
Feed/

What is the null pointer in C++? A null pointer is a kind of pointer that does not currently points to any memory location. In previous version of C++, a null pointer was initialized with null. But in the modern C++, we use the null PTR to represent or initialize a null pointer. Like here, PTR is a null pointer. Now if we try to de-reference a null pointer, then it will result in an undefined behavior. Null pointer are commonly used to initialize a pointer. It can be used with the conditions to check if pointer is a null pointer or not. This is a practical example. In this line we have created a memory on the heap and the PTR pointer is pointing into it. Then we deleted the memory from the heap. At this point, pointer PTR becomes a dangling pointer. Then we assigned inl_ptr to this PTR and this line will make PTR inl_pointer. We can safely delete inl_pointer. It will not result in any undefined behavior.

"What is the null pointer in C++?"

👍
0
0 comments0 shares

Sign in to view and post comments.