Question: ```
int main(){
MyBase *mb;
int choice;

cout << "Select: ";
cin >> choice;

switch (choice) {
    case 1:
        mb = new Test1();
        break;
    case 2:
        mb = new Test2();
        break;
    case 3:
        mb = new Test3();
        break;
    case 4:
        mb = new Test4();
        break;
    case 5:
        mb = new Test5();
        break;
    case 6:{
        LinkTest t;
        t.start();
        break;
    }
    default:
        return 0;
}

if(mb != 0){
    mb->start();
    delete mb;     
}

return 0;
}

```

If choice is 6, why am I getting a segmentation fault when checking if mb is NULL?

I am new to c++ and just doing some exercises. 
How can I fix this without affecting the class LinkTest?
Thanks.

Answer: 
You haven't initialized `mb`; C++ doesn't do that for you; and for the case that `choice` is 6, `mb` doesn't get assigned any value, so it is uninitialized later on when you check it against 0, and can hold any random value (that random value could be 0, but in most cases it won't be; it will just contain whatever value there was in the part of memory where the variable now is).
Try

```
MyBase *mb = NULL;

```
You need to initialise mb to `NULL`, otherwise in the case where `choice` is not in the range 1..5 `mb` will be undefined. Change:

```
MyBase *mb;

```

to:

```
MyBase *mb = NULL;

```