NULL pointer and deleting it [duplicate] - c++

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Is there any reason to check for a NULL pointer before deleting ?
Is there a bug in this code
Type * p = 0;
delete p;
p is a null pointer here. will there be any issues in implementing this.

No, it's specified in the C++ specification that delete on a null pointer does nothing.

Related

Dereferencing a function pointer, C++ [duplicate]

This question already has answers here:
How does dereferencing of a function pointer happen?
(5 answers)
Calling a function through a function pointer - dereference the pointer or not? What's the difference?
(2 answers)
Closed 12 months ago.
what's the difference between the second and third line:
int (*myFunction)() = fooFunction;
(*fooFunction)();
fooFunction();
Why do both do the same thing? Is it just how C++'s syntax is? I thought that a function pointer needs to be dereferenced in order to call it. How does the third line work, it isn't dereferenced.

C++: Convert value int (For example: 0x00AAFAD8) to pointer (Also the pointer itself is the 0x00AAFAD8 value) [duplicate]

This question already has answers here:
Can I directly assign an address to a pointer? If so, how to do that?
(2 answers)
Closed 2 years ago.
i want to Convert value int (For example: 0x00AAFAD8) to pointer (Also the pointer itself is the 0x00AAFAD8 value). I don't know how it's called, so i want help for manage memory spaces by values like this.
Thanks.
You can set the pointer address this way:
int i = 0x00AAFAD8;
int* ptr = reinterpret_cast<int*>(i);

Is nullptr the same as zero? [duplicate]

This question already has answers here:
What exactly is nullptr?
(14 answers)
Do you use NULL or 0 (zero) for pointers in C++?
(21 answers)
What is the difference between NULL, '\0' and 0?
(11 answers)
Closed 3 years ago.
I am currently learning C++ and have gotten to pointers. I am struggling to understand the difference between initializing a pointer to zero and initializing it to nullptr, as demonstrated below.
int *p = 0;
int *p1 = nullptr;
My understanding is that p and p1 are both null pointers. Does this mean that nullptr is equivalent to zero, and that both p and p1 are pointing to the same address (that is, the address for zero)?
If they are the same, why would I want to use nullptr when I could just use zero? If they aren't the same, why is it useful to have multiple ways to declare a null pointer instead of one way?

Is deleting a null pointer in C++ considered undefined behaviour? [duplicate]

This question already has answers here:
Is it safe to delete a NULL pointer?
(8 answers)
Test for void pointer in C++ before deleting
(3 answers)
Closed 8 years ago.
Consider the following piece of code:
int main() {
int *i = nullptr;
delete i;
}
Questions:
Is deleting a null pointer considered undefined behaviour?
Did something changed in C++11 or C++14?
Is deleting a NULL pointer in C++ considered undefined behaviour?
No, this is perfectly legal operation.
From N3242, [expr.delete]
the value of the operand of delete may be a null pointer
value

C++ ClassName::GetSth(TypeName* &pSth) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
what’s the meaning of *&
what * &pSth mean?
is this a pointer or a ref?
Why/When we need that?
--code--
ClassName::GetSth(TypeName* &pSth)
{
//some code
}
It means "reference to pointer to Typename".
TypeName* &pSth is a reference to TypeName pointer.
Equivalent syntax in C is TypeName** pSth