Skip to Content
Advanced C++ Programming Cookbook
book

Advanced C++ Programming Cookbook

by Dr. Rian Quinn
January 2020
Intermediate to advanced
454 pages
11h 25m
English
Packt Publishing
Content preview from Advanced C++ Programming Cookbook

Null-pointer dereferences

A more common type of problem in C++ is a null-pointer dereference, as follows:

int main(void){    int *p = 0;    *p = 42;}

This results in the following:

In the preceding example, we create a pointer to an integer and set it to 0 (that is, a NULL pointer). We then dereference the NULL pointer and set its value, resulting in a segmentation fault, which UBSAN is capable of detecting as the program crashes.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern C++ Programming Cookbook

Modern C++ Programming Cookbook

Marius Bancila

Publisher Resources

ISBN: 9781838559915Supplemental Content