@JM
You have been told before - don't post advice to others, because you don't know what you are talking about.
Is it any wonder that people think you are a troll? Unless you behaviour changes, you are on a thin edge of being reported as such.
In this case, the use of parentheses does nothing at all.
@jkfde
*pint
is OK, it fetches the integer value at the address pointed to by pint. pint is the pointer variable and contains a memory address. If you did
pint = 100;
this would attempt to assign 100 to the pointer, which should result in an error.
The first problem is that if the new operator fails, then C++ would throw an exception, making any later error trapping code pointless. To fix this you would need to enclose line 4 in a try / catch block and catch the exception yourself. Mind you if this happens, you have much bigger problems I think.
In my mind, error processing should be done first then code is allowed to continue if everything is OK:
1 2 3 4
|
if(there-is-an-error) {
//process the error
}
//everything OK, so continue
|
The example in your post is backwards in this respect.
The declaration / initialisation of the pointer can all be done on one line, and you can put this in the try block:
1 2
|
int *pMyInt = new int(100);
|
The use of NULL is discouraged because it is not type safe and is sometimes interpreted as 0 or a pointer to void. C++11 has nullptr which is designed to fix this problem. Although you shouldn't need this in the code if exceptions are being used, just added it for your education.
Hope all this helps.