I am trying to run the following program :
#include <iostream>
struct Foo {
int x;
void bar() {
std::cout << "La la la" << std::endl;
}
void baz() {
std::cout << x << std::endl;
}
};
int main() {
Foo *foo = NULL;
foo->bar();
foo->baz();
}
Output
:
./a.out
La la la
Segmentation fault (core dumped)
I am using g++ version 7.3.0 on ubuntu 18.04. Shouldn't both the calls fail as the object has been set to null?