O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pointers Are Dangerous

Remember that the compiler doesn't care if you try to get or put the value of an element that is outside an array's size. This is because arrays are really convenient shorthand for pointers.

Pointers are just as dangerous as arrays for the same reasons. Have a look at this:

char *SomePointer;
*SomePointer = 'x'; // Oops.

What do you think this does? If you answer, “I don't know,” you're right. The behavior of a program with an uninitialized pointer is undefined and unpredictable.

char *SomePointer = NULL;
*SomePointer = 'x'; // Oops.

In this case, NULL means “points to nothing.” If you are lucky, the program stops. If you are unlucky, your entire system may freeze or crash. Still, NULL is often used to indicate that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required