I have a little problem. way back in high school I took java, and never had to deal with these little things. now, at college, they're making me take C. I don't have anything against it, its just that.. well I'm not entirely sure what pointers are used for, or what they accomplish. would anyone care to elighten me?
Name:
Anonymous2006-11-02 15:06
A pointer is a variable which, instead of holding a value you work with, holds the position in memory where the value you actually want is. When-
Wait. Why don't you RTFM? There are many good C tutorials in the net, they're better than what I was going to say, just Google, it'll do ya good.
>>5
That's C++, not C. And you should return EXIT_SUCCESS rather than 0. >>6
In Java, there are only pointers to structs, to put it shortly. I like it better than the C++ systems, but C is just fine.
A C pointer contains an address in your memory, just like an index in a array the size of your memory.
As EXIT_SUCCESS is always defined as 0, it doesn't make any difference which one you use. Any decent programmer is going to know what "return 0" means from main().
- Pointers contain the memory location of a variable, rather than the value of the variable itself.
- Pointers have types (i.e., there are int pointers, float pointers, struct WHATEVER pointers, class WHATEVER pointers)
- There are even void pointers.
- Pointers can be assigned to each other, added to, and subtracted from.
- You can "deference" a pointer to get the value that it's pointing to.
- When you don't want a pointer to point to anything, set it to 0.
- Deferencing a 0 or null pointer generally has bad consequences.
- Array notation is just a different style of pointer notation, i.e., array[7] = *array + 7. Pointer notation is faster.
- You can get a pointer to a function using pointer syntax. It's a void pointer.
- Yes, you can even call functions via pointers, like *funcpointer(arg,arg,arg...)
- Yes, you can have an array of void pointers and use them to call functions
- Yes, you can have pointers to pointers and pointers to pointers to pointers. Linked lists, do you use it motherfucker.
Name:
Anonymous2006-11-03 12:39
>>Array notation is just a different style of pointer notation, i.e., array[7] = *array + 7. Pointer notation is faster.
1) You mean *(array + 7) ... *array + 7 will dereference *array and add 7 to that value.
2) Notation doesn't affect speed -- array[7] and *(array + 7) will compile into the same assembly. Oh it may affect compilation speed, if this was like 20 years ago and we're working on shitty little steam-powered Tandy computers.
Name:
Anonymous2006-11-03 13:12
>>15
I wouldn't recommend pointer arithmetic to newbies.
Pointed functions are made of win.
Also, you can link your programs with efence to test them, it will make the program crash at the first seg fault (and not miles after leaving you with no clue on how it happened).
Name:
Anonymous2006-11-03 13:14
I get such a raging hardon for steam powered tandys
>>22
It was not by my hand that I am once again given cycles. I was called here by... _Kernighan_, who wished to pay me tribute.
Name:
Anonymous2009-01-14 15:14
GTFO
Name:
Anonymous2009-03-06 11:31
What kind of person actually cooks these things up in your computer right now monitoring your every move on from writing things in BASIC I e you have to understand that the Japanese Government resinded the law protecting trade secrets.
Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy