Dec 09 2012, 03:01 AM
Dec 09 2012, 03:20 AM
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 .
Dec 24 2012, 03:35 PM
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".
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".
Dec 24 2012, 03:45 PM
Okay thanks got it straight
Nov 26 2013, 04:39 AM
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.
Nov 26 2013, 05:00 AM
so you necro-ed an 11 months old Programming thread pish?
Nov 26 2013, 05:18 AM
i just got back! gimme a break havent gamed or been here in months, plus this was more for anyone else coming across this thread in the future, like i did