Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Explain C Pointers
#1
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.
[Image: 629965_101.png][Image: dav8ugf75d010z8vovm.gif]
#2
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 .
[Image: sigix.png]
#3
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".
#4
Okay thanks got it straight Big Grin
[Image: 629965_101.png][Image: dav8ugf75d010z8vovm.gif]
#5
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.
[Image: tumblr_m8wz8pZhho1qe7ttxo1_500.jpg]
#6
so you necro-ed an 11 months old Programming thread pish?
be the best version of yourself, that's all you can do.
#7
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
[Image: tumblr_m8wz8pZhho1qe7ttxo1_500.jpg]

Users browsing this thread: 3 Guest(s)