Stack Exchange
EXC_BAD_ACCESS (EXC_i386_GPFLT) when inserting node in BST
I'm trying to populate Binary Search tree from given array in XCode via C++.
I'm using recursion to generate BST in following way.
int main(int argc, const char * argv[]) {
    const int length = 19;
        int data[length] = {1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20};
        Node* root = new Node(12);

        for(int i = 0;i<length;i++){
            insert(data[i], &root);
        }
return 0;
}

and here is my insert function
void insert(int key, Node **current)
{
    if(*current == NULL)
    {
        Node *newnode = new Node(key);
        *current = newnode;
    }
    else
    {
        if(key < (*current)->value) ---------EXCEPTION HERE
            insert(key, &(*current)->left);
        else
            insert(key, &(*current)->right);
    }
}

sometimes it throws an exception EXC_BAD_ACCESS (code = EXC_i386_GPFLT).
The same logic works fine in Visual Studio with C#.
Am i doing something wrong with memory in c++?
I'm not so much familiar with c++, but seems everything should work. 

You must show the declaration and the definition of the Node class. The most likely answer is that left and right are not getting explicitly initialized to nullptr.

exactly!. it was
Node(int _value){
value = _value;
}

you can write  it as an answer that i could mark it as answered.

After applying the Sherlock Holmes approach to bug hunting(1), the most likely explanation was that left and right class members were not getting explicitly initialized to nullptr.
(1) "Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth."
