NullPointer - 4. add NULL pointer check int *p2 = new int ;...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> using namespace std ; int main() { int x = 1, y = 2, z = 3 ; int *p = &x ; cout << "p: " << p << ", *p: " << *p << endl ; } /* 1. with initialization of p 2. without initialization of p 3. set p to NULL initially
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 4. add NULL pointer check int *p2 = new int ; if (p2 == NULL) { cout << "Memory allocation failed." << endl ; } *p2 = z ; cout << "*p2 = " << *p2 << endl ; */...
View Full Document

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Ask a homework question - tutors are online