#include using namespace std; class BankAccount { public: BankAccount(); void deposit(int amount); int get_balance() const; private: int balance; }; BankAccount::BankAccount() : balance(0) {} void BankAccount::deposit(int amount) { balance = balance + amount; } int BankAccount::get_balance() const { return balance; } int main() { // We deposit an uninitialized value into the first account cout << "Using an uninitialized integer: "; BankAccount* harrys_account; int amount; harrys_account = new BankAccount(); harrys_account->deposit(amount); cout << harrys_account->get_balance() << endl; // We make a method call through the uninitialized pointer cout << "Using an uninitialized pointer: "; BankAccount* sallys_account; cout << sallys_account->get_balance() << endl; } /* Output: An uninitialized integer: 4301064 An uninitialized pointer: (program crashed) Explanation: In C++, variables on the stack are not initialized by default. They simply start out with whatever value happens to be in the stack area that they occupy. In this example, we first make an output statement so that the stack gets cluttered. Then we allocate an integer and "forget" to initialize it. The result is simply a random-looking value. More disturbingly, the value can be seemingly reasonable-looking in some program runs. Uninitialized pointers can be more dangerous. Depending on the program run, they may point into valid or invalid memory. In the former case, a random memory block is being addressed. In the latter, the program crashes with a processor exception. */