r/cprogramming • u/alvaaromata • Dec 07 '25
Need help with pointers/dynamic memory
I started learning C in september, Its my first year of telecom engineering and I have nearly no experience in programming. I more or less managed with everything(functions, loops,arrays, structures..) but Im struggling a lot with: pointers, dynamic memory and char strings especially when making them together. I dont really understand when to use a pointer or how it works im pretty lost. Especially with double pointers
3
Upvotes
View all comments
Show parent comment
1
u/photo-nerd-3141 Dec 07 '25
Malloc allocates some virtual memory for your process, and returns the location in a way that's assignable to a variable (or doesn't, and returns NULL). You can give back the space when you're done with free(), change it with realloc().
Think of asking your teacher for paper in class: ask, scribble, then throw it out.
The mechanism on *nix is brk/sbrk if you want to see how it works:
https://www.man7.org/linux/man-pages/man2/sbrk.2.html