Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6623409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:31:46+00:00 2026-05-25T21:31:46+00:00

Why am I getting an access violation reading location 0xC0000005 here if the same

  • 0

Why am I getting an access violation reading location 0xC0000005 here if the same code works like a charm when I coding in linux?

if(nodo->izq!=NULL) //nodo is a class or struct and "sig" is a pointer of the same kind
    VaciarAux(nodo->izq);

Is there any way of getting this done without that unhandled exception?
assert will do the trick?

here is the function

void Arbol<T>::VaciarAux(Nodo<T> * &nodo)
{
    if(nodo->izq!=NULL)
        VaciarAux(nodo->izq);
    if(nodo->der!=NULL)
        VaciarAux(nodo->der);
    if(nodo->izq == NULL && nodo->der ==NULL)
    {
        actual = nodo;
        nodo=NULL;
        delete actual;
        contador--;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:31:46+00:00Added an answer on May 25, 2026 at 9:31 pm

    Most likely because nodo itself is an invalid pointer. The -> dereferencing would then cause a problem.

    You need to check the things that could possibly affect that value (buffer overflows causing corruption, having set to NULL for some reason).

    Note that:

    if (nodo->izq != NULL)
    

    does not check if the nodo variable is NULL but rather if the izq member of what nodo points to is NULL.

    If you simply want to do nothing if nodo itself is NULL, you could put at the start:

    if (nodo == NULL) return;
    

    but I still think you’d be much better off tracking back to the source of the problem rather than just fixing one symptom.


    I think the problem is with the way you are processing the tree. You are effectively doing:

    def delTree (node):
        if node.left != NULL:
            delTree (node.left)
        if node.right != NULL:
            delTree (node.right)
        if node.left == NULL and node.right == NULL:
            delete node and whatever else you have to do
    

    The main problem with that is that delTree (node.left) means that you’ll get the exact problem you’re seeing if the tree is empty since the first thing you try to do is dereference the NULL root node.

    The more usual approach is to first recur the children unconditionally (with a NULL protector) then process the node itself, something like:

    def delTree (node):
        if node == NULL:
            return
        delTree (node.left)
        delTree (node.right)
        delete node and whatever else you have to do
    

    This will correctly handle an empty tree and still correctly delete all children before the parent. And it just looks more elegant, which is one of the reasons to use recursion in the first place 🙂

    I’ll leave it as an exercise for the reader to turn that back into C++.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting access violation exceptions when running the code below when the CertFreeCertificateContext
I'm getting an Access Violation in DBEXPSDA40.DLL (Dev Art MS SQL Server dbexpress driver)
I am getting an error: Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You
I am getting an access violation error in an unmanaged dll I am writing,
Hi I am getting an access violation error..... What might be the problem in
Im getting the following Access violation at address 00404340 in module 'test.exe'. Read of
I'm getting a weird access violation at the end of my main whose cause
I am getting Access violation error from the debugger, but I really have no
I am continuously getting an Access Violation Error with a all my kernels which
I'm getting a (to me) weird run-time access violation error. I have a class,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.