#Pointer Pain

33 messages · Page 1 of 1 (latest)

echo raven
#

So I need to add two non empty linked lists. A created an add function which adds the two digits from my linked list and store the answer digit in a new linked list. So to accomplish this, I need to pass a double pointer as an argument in my function and I am passing either the "head" pointer or "tail" pointer of my answer linked list. However I am facing an error at line 27.

sick wagonBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

glacial pond
#

*ans is a LinkedList*, since ans is a `LinkedList**~

echo raven
#

Yeah so the -> operator should work right?

#

But it isn't.

proper tide
#

(*ans)-> next

glacial pond
#

(*ans)-> should work

#

frick sniped

echo raven
#

Nah it ain't working.

glacial pond
#

It's working as in it's compiling. It just means your code is valid, but incorrect.

proper tide
#

Maybe dereferencing a null pointer somewhere

echo raven
#

I guess that might be the issue.

glacial pond
#

No. You're using a pointer that you already deleted

#

Compile with debug symbols and it should show you where you're trying to access it at

echo raven
#

Can you guys help me debug it?

glacial pond
#

looks like homework

proper tide
#

Nah it’s just lc

echo raven
#

Yeah its leet code.

glacial pond
#

yeah, I don't touch LC very intentionally. good luck

proper tide
#

Debugging in LC sucks. You should probably run it on your own machine with GDB or some other debugger

echo raven
#

Hmm... I made sure that I am not dereferencing a null pointer.

echo raven
glacial pond
echo raven
#

Wait, so it apparently says I am using a heap memory after freeing it? But I ain't freeing anything.

echo raven
#

But only after executing the program right?

oblique swallow
#

no

#

when it ends a task

#

use smart pointers

echo raven
#

Well I was thinking of doing some optimisation but looks like I have to do it the old fashioned way.

#

Thanks for your help everyone.

#

!solved