Trouble with pointers
-
- Posts: 9
- Joined: Oct 26, 2010 4:06
- Location: Noneya,BS
Trouble with pointers
I'm having trouble understanding pointers in freeBASIC can someone please illustrate some uses of pointers and the syntax
Take a look at;
http://www.freebasic.net/wiki/wikka.php ... PgPointers
then ask a more specific question.
http://www.freebasic.net/wiki/wikka.php ... PgPointers
then ask a more specific question.
-
- Posts: 9
- Joined: Oct 26, 2010 4:06
- Location: Noneya,BS
Pointers are not essential when programming in FB. They do not control program flow, they are memory addresses of data. Pointers are supported in FB to be compatible with external libraries and languages such as C.
http://en.wikipedia.org/wiki/Pointer_%28computing%29
http://en.wikipedia.org/wiki/Pointer_%2 ... g%29#BASIC
http://en.wikipedia.org/wiki/Pointer_%28computing%29
http://en.wikipedia.org/wiki/Pointer_%2 ... g%29#BASIC
Sometimes you know when writing a program how much data you are going to need to store in variables, so you can use simple variables defined like this:Joshua50187 wrote:Ok can some one elaborate on some of the uses of pointers and how they can effect the flow of the program
Dim as integer x
or perhaps arrays defined like this
dim as integer y(1 to 25000)
but sometimes you don't know how much data there will be until the program runs. This is a use for pointers. (note: this is a bit of a simplification since the size of arrays can also be changed at run time) Like so:
dim as integer n
dim as single pointer s
input "how many singles do you need to store?",n
s = allocate(n * sizeof(single))
also helps you to create data structures like linked lists and trees
http://en.wikipedia.org/wiki/Linked_list
http://en.wikipedia.org/wiki/Binary_tree