I get what they do, if im not mistaken they point to the adress at which data is stored, im just wondering what they are useful for? we dont use them in scar? and so im interested in their uses....
Mat
I get what they do, if im not mistaken they point to the adress at which data is stored, im just wondering what they are useful for? we dont use them in scar? and so im interested in their uses....
Mat
The truth finally came out...
they do point to the address of a variable, and they are useful for a few reasons, heres some
its much easier to copy the referance than the whole variable, so when you call a method with a string, its faster to pass a pointer-to-string than the whole string, that way you copy only a 32-bit number, instead of a whole array of characters
also, you can add and subtract pointers, so its a bit better than accessing arrays and places in strings, heres an example
(btw, i dont know c++ syntax too well.. hopefully it wont show)
its much faster to increment a pointer then go along in the arrayCode:int myArray[10]; int* pointerToArray = &myArray; for(int f = 0; f < 10; f++) { cout << "index = " << f << " is " << *pointerToArray[0] << endl; pointerToArray++; }
Join the Official SRL IRC channel. Learn how to Here.
Pointers are like... Having WT-Fakawi teaching you SCAR. Yes, they are that awesome.
The jealous temper of mankind, ever more disposed to censure than
to praise the work of others, has constantly made the pursuit of new
methods and systems no less perilous than the search after unknown
lands and seas.
Sorry to be a pain but this the way this has been expressed is potentially confusing.
A pointer contains an address. This is an address in memory. What is contained at this address could be anything. It could be an integer (or even another address).
They do NOT point to the address of a variable. They contain an address. When defined as a pointer the compiler will know to treat them as a pointer and know that what they contain is an address and reference the address.
If a pointer pointed to the address of a variable it would be a pointer to a pointer. (This is possible and is often used but is not what a pointer is). It contains the address - it doesn't point to it. A pointer simply contains an address.
They are not used in SCAR and SRL because these languages abstract that level of detail away.
If you wish to know more then I would suggest that you type 'c programming' into Google (or whatever) and see what you can find.
To start you off try this
http://www.cs.cf.ac.uk/Dave/C/node10...00000000000000
btw - hope this is helpful and not confusing (and hope even more that it is correct). Apologies if I have failed in any of these aims
Paul
Might as well explain offsets while your at it, eh?
The jealous temper of mankind, ever more disposed to censure than
to praise the work of others, has constantly made the pursuit of new
methods and systems no less perilous than the search after unknown
lands and seas.
Robot,
quite happy to explain offsets. But just to be sure I'm answering the correct question, can you explain a little further, maybe with an example what exactly you wish to know.
Paul
I knew thatjust didnt explain it properly thanks anyway
The truth finally came out...
Okay Mat, no problem
It is just that in C and with tricky subject like pointers I have found over the years that it is important to be very precise. Pointers like the opportunity to misbehave if you give them any chance at all.
Paul
There are currently 1 users browsing this thread. (0 members and 1 guests)