Pointers WTF?
Posted: Fri Nov 07, 2008 8:58 pm
Can someone PLEASE explain to me what pointers are and WHY you need them? It doesn't make sense! They just make things more complex. But I understand they are used in SDL quite often.
The Next Generation of 2D Roleplaying Games
http://elysianshadows.com/phpBB3/
i have a thread about pointers that i update regularly.JaxDragon wrote:Can someone PLEASE explain to me what pointers are and WHY you need them? It doesn't make sense! They just make things more complex. But I understand they are used in SDL quite often.
Code: Select all
struct element {
struct element *next;
int value;
};
struct element *head = NULL;
void insert(struct element *item) {
struct element **p;
for(p = &head; *p != NULL; p = &(*p)->next) {
if(item->value <= (*p)->value) {
break;
}
}
item->next = *p;
*p = item;
}
off wiki//
Pointers are directly supported without restrictions in languages such as C, C++, Pascal and most assembly languages. They are primarily used for constructing references, which in turn are fundamental to constructing nearly all data structures, as well as in passing data between different parts of a program.
In functional programming languages that rely heavily on lists, pointers and references are managed abstractly by the language using internal constructs like cons.
When dealing with arrays, the critical lookup operation typically involves a stage called address calculation which involves constructing a pointer to the desired data element in the array. In other data structures, such as linked lists, pointers are used as references to explicitly tie one piece of the structure to another.
Pointers are used to pass parameters by reference. This is useful if we want a function's modifications to a parameter to be visible to the function's caller. This is also useful for returning multiple values from a function.
thats gonna happen, that still happens to me. post your code and i'll let you know what you are doing wrong.JaxDragon wrote:I think C++ officially hates me. I tried referencing pointers and stuff, and got loads of errors, *panics*
Pointers are a confusing subject, they certainly make C++ much more difficult, by god don't they make so many more things possible?JaxDragon wrote:I think C++ officially hates me. I tried referencing pointers and stuff, and got loads of errors, *panics*
Post code segments and we can explain what you are doing wrong.JaxDragon wrote:I think C++ officially hates me. I tried referencing pointers and stuff, and got loads of errors, *panics*
Har, pun now intended.I think there's a point in everybody's life when the concept of pointers just kinda 'clicks'.