Trouble with pointers

New to FreeBASIC? Post your questions here.
Post Reply
Joshua50187
Posts: 9
Joined: Oct 26, 2010 4:06
Location: Noneya,BS

Trouble with pointers

Post by Joshua50187 »

I'm having trouble understanding pointers in freeBASIC can someone please illustrate some uses of pointers and the syntax
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Post by Richard »

Take a look at;
http://www.freebasic.net/wiki/wikka.php ... PgPointers
then ask a more specific question.
Joshua50187
Posts: 9
Joined: Oct 26, 2010 4:06
Location: Noneya,BS

Post by Joshua50187 »

Ok can some one elaborate on some of the uses of pointers and how they can effect the flow of the program
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Post by Richard »

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
j_milton
Posts: 458
Joined: Feb 11, 2010 17:35

Post by j_milton »

Joshua50187 wrote:Ok can some one elaborate on some of the uses of pointers and how they can effect the flow of the program
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:
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
Post Reply