(wL) Forums

Full Version: Explain C Pointers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Guys I got stuck at a question that y do programmers need the values address:confused:?Please explain in detail cause I am new to C.
Don't really know too much about pointers, but I believe it is mainly to enhance performance, and to utilize complex data types that would otherwise be impossible without them. Someone please correct me if I'm wrong .
There's a couple of reasons.

You can pass pointers around to functions and methods to work on variables by reference instead of by value so changing anything at that pointer will change the value of the variable you passed outside the function too.

Another thing you can do with pointers is change it's data type. For instance if you're working with network data you'll typically read the data into a byte array then change that byte array into a struct so you can start using the data how it's meant to be used. The byte array data type can't be recast into a struct, that's why you have pointers, you take the raw data in memory and say "this raw data is a struct".
Okay thanks got it straight Big Grin
To expand on that, pointers are also used for dynamic memory allocation. You can create variables (arrays, structs, objects, vectors etc...) all during runtime which allows for much better memory management. You can not only create these real time, but you can also destroy them which gives the memory back to the heap.
so you necro-ed an 11 months old Programming thread pish?
i just got back! gimme a break Wink havent gamed or been here in months, plus this was more for anyone else coming across this thread in the future, like i did Wink