It looks like you are using a Sams C++ book. By the look of the example code I'd say you are using the eighth edition of "Sams Teach Yourself C++ in One Hour a Day."
I have the seventh edition and 8.13 shows BAD code, creates an invalid pointer.
Some current C++ compilers get all huffy about uninitialized variables and stray/invalid pointers as well as a lot of other things. Are you using Visual Studio 2017/2019? That is one of the compilers that complain. A lot.
#include <iostream>
usingnamespace std;
int main()
{
// always initialise to nullptr if there is no other option
bool *isSunny = nullptr;
cout << "Is it sunny (y/n)? ";
char userInput = 'y';
cin >> userInput;
if (userInput == 'y') {
isSunny = newbool;
*isSunny = true;
}
// Use short-circuit evaluation.
// If the pointer is still nullptr, then it won't be dereferenced
cout << "Boolean flag sunny says: " << (isSunny && *isSunny) << endl;
// delete nullptr is a safe no operation.
delete isSunny;
return 0;
}
The p && *p is a common way to first test a pointer is valid before going on to dereference it in some way.