The language feature you are looking for is called "if".
It allows to test a logical condition and then execute code depending on whether the expression evalutes to "true" or "false".
if (condition) {
// code executed when the condition is true
} else {
// code executed when the condition is false
}
if (condition) {
// code executed when the condition is true
} else {
// code executed when the condition is false
}
To copy to clipboard, switch view to plain text mode
The "else" case is optional.
In your case you can either check for the pointer being null and the code to execute being "return" or you can check for not being null and executing the code that uses the pointer.
Cheers,
_
P.S.: I would strongly recommend to work through a tutorial on C++ basics before continuing.
Bookmarks