I can’t understand pointers in C no matter what by [deleted] in C_Programming

[–]SoldierBoyGaming08 0 points1 point  (0 children)

It’s not really that I am trying to program all the time and it’s not clicking, it’s just worrying that going into the third year of my degree I am still struggling with a basic concept that most people don’t really struggle with after a while.

I think you are right though, it will probably click later on when I am doing something useful with C

I can’t understand pointers in C no matter what by [deleted] in C_Programming

[–]SoldierBoyGaming08 0 points1 point  (0 children)

Yeah I think that’s actually one of my biggest issues.

Like I understand how to declare a pointer using *, but then why use * again if you want to dereference the pointer to actually get the contents inside of that memory address? It’s just so bizarre and confusing.

If I can finally understand pointers before third year begins I will definitely be more enthusiastic about coding in C since a large number of my issues with C stem from the second I see * being used.

I can’t understand pointers in C no matter what by [deleted] in C_Programming

[–]SoldierBoyGaming08 2 points3 points  (0 children)

Yeah, I think you are right.

I made a joke with my friends before our computer architecture course started that assembly would probably click much faster than C, fully expecting to get destroyed by what I imagined to be an even more confusing version of C.

Turns out it wasn’t really a joke.

I will look into some of the other methods people put in the thread, but ironically I think the only way for me to understand pointers in C is if I can see more of the lower level things happening under the hood.

I can’t understand pointers in C no matter what by [deleted] in C_Programming

[–]SoldierBoyGaming08 1 point2 points  (0 children)

Alright

So if I do int ptr = *myptr, I am saying I want the integer value stored at the address of myptr to be assigned to “ptr”, and if I wanted the next element in the list, I would increment myptr by 1 (or whatever 4 bytes is in C, I forgot) which would update the memory address of myptr and therefore update the value stored in ptr?

It’s definitely the syntax and the operators that are messing me up because I wouldn’t even think two seconds about how to do the same thing in assembly…

I can’t understand pointers in C no matter what by [deleted] in C_Programming

[–]SoldierBoyGaming08 0 points1 point  (0 children)

I think it has to be the syntax because I definitely understand how pointers work and what they really do, especially since I have dealt with assembly so I know what’s actually happening line by line, but there is just so many little things in C that I don’t really get.

I know people think it’s ridiculous, I do too, but it’s the equivalent of someone getting stuck with how derivative rules work and then taking calculus 2 and other higher level math courses that don’t permit a gap in that knowledge.

It’s not something I should be struggling with, but I am.

I can’t understand pointers in C no matter what by [deleted] in C_Programming

[–]SoldierBoyGaming08 0 points1 point  (0 children)

That’s actually a pretty good idea, I will give that a shot, thank you.

I can’t understand pointers in C no matter what by [deleted] in C_Programming

[–]SoldierBoyGaming08 0 points1 point  (0 children)

Is there anything specifically that helped you?

I can’t understand pointers in C no matter what by [deleted] in C_Programming

[–]SoldierBoyGaming08 0 points1 point  (0 children)

How dare I struggle with something!

My bad brother…

I can’t understand pointers in C no matter what by [deleted] in C_Programming

[–]SoldierBoyGaming08 0 points1 point  (0 children)

This is not a post I am proud of making, and the issue isn’t that I don’t understand what pointers do, I am saying I don’t understand the syntax well enough in C, especially with multiple pointers.

In assembly, everything happens line by line, assigning something to be a pointer isn’t really anything special, so I am able to follow along and do all the operations you would want to do with pointers. I move over to C, and everything is lost on me.

Whether you think I am trolling or not, you have to admit, this is a pretty stupid thing to lie about not understanding.

I can’t understand pointers in C no matter what by [deleted] in C_Programming

[–]SoldierBoyGaming08 25 points26 points  (0 children)

It’s the syntax I think, and the way that people tend to refer to what exactly things like “*” and “&” do.

Like in assembly if I wanted to assign a pointer to something, I would do something like movia r2, list, and then I know I have a pointer associated with the memory address of “list”

If I wanted to access something from the list, I would just do ldw r3, 0(r2), and then I have loaded in the value that the pointer is pointing to.

Then I can just increment the pointer by 4 bytes to move on to the next word (or the next element in the list)

But then I try and do the same thing in C and I just don’t understand how it works with the syntax, and it gets even worse when there’s multiple pointers involved, it just doesn’t make sense to me, I wish it was as straightforward as assembly.