What is Pointer ? 
Author Message
 What is Pointer ?

Could anyone explain, what a Pointer is,
and how it does work ?


Wed, 18 Jun 1902 08:00:00 GMT  
 What is Pointer ?

Quote:

> Could anyone explain, what a Pointer is,
> and how it does work ?

        Put simply, a pointer is a variable that stores a memory
location. What's the point of it? Well, it tells where you can store a
variable. The basic idea is that you tell tp to make some space for the
pointer and then the pointer variable points to that area of space.
That's the first part...
        The second part is that the pointer -should- point with a
certain variable type. For example, we could tell TP to make room for
our pointer called newptr by saying "new(newptr);". So now we have
newptr pointing to some space in memory. BUT what can we store in that
space? It all depends on the declaration. The declaration for NewPtr
would look like this...

        var newptr:ptr;

...but what does it doooo??? Nothing. It just sits there, telling us
we've got some space in mem where something -could- go. So, what we do
is have a pointer that points to a variable type. For example, we could
have a pointer called BytePtr that points to a byte. This means that
when we tell tp to make a new(byteptr), it assigns a space that a
variable of type Byte can be stored in. Declaration...

        var BytePtr:^byte;

...the "^" or karat means "points to a variable of type..".

        I guess this is the basic idea behind pointers. If you can
understand this on the first go, then you're starting on one of the
'Pilars of Pascal' as it's called.

optional info...Pointers are the base for dynamic arrays (linked lists),
stacks, queues, and binary trees.
        Hope this helps....ciao!

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-       Paul Matthews - Lead Programmer : Creative Logic Software
        Check out the ALL NEW Creative Logic Software Homepage!
                 http://www.singnet.com.sg/~pmatth/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



Wed, 18 Jun 1902 08:00:00 GMT  
 What is Pointer ?

Quote:

> Could anyone explain, what a Pointer is,
> and how it does work ?

A pointer is a type used to allocate disk space that
can vary in size at run time,
here is some sample code I wrote that you can use to
get a feel for pointers...

Program Linked_list (Input, Output);
Uses Crt;
Type
   NamesPtr = ^Names_Record;       {the pointer!}
   Names_Record = Record
               FirstN: String;
               LastN : String;
               Next  : NamesPtr;   {pointer to the next record}
          End;
Var
   Names: Names_Record;
   First_Name, Last_Name: String;
   First, Last, Current: NamesPtr;  {first will be set to the first pointer
                                    on the list (used to reset the list) }
                                    {current is the moving pointer whose
                                    value changes}
                                    {Last is the last member of the list
                                    that can be used in displaying the member
                                    of the list}
   Another: Boolean;
   Ans: Char;
   I: Integer;
Begin
   Another:= true;
   ClrScr;
   I:= 1;
   Repeat
      ClrScr;
      If (I = 1) then
         begin
            New(First);              {Allocates memory for the first pointer}
            Current:= First;   {Moving pointer set to first member of the list}
         End;
      If (I > 1) then Current:= Current^.Next;    {Moves the current memory
                                                   pointer to the next one }

      Write ('Enter a first name: ');
      Readln (First_Name);
      Current^.FirstN:= First_Name;  {Syntax is pointer_name^.record_variable}

      Write ('Enter a last name: ');
      Readln (Last_Name);
      Current^.LastN:= Last_Name;

      Write ('Another (Y/N): ');
      Readln (Ans);
      If (Ans = 'N') or (Ans = 'n') then Another:= false;
      Inc(I);
   until (Another = false);
   Last:= Current;      {Variable for the last member of the list for later use}

   Current:= First;   {Moving pointer set to begining of list}
   ClrScr;
   Repeat
      Writeln (Current^.FirstN,' ',Current^.LastN);    {Displays the first and
last
                                                       names of the current
record pointer}
      Current:= Current^.Next;    {moves current to the next on the list}
   Until Current = Nil;        {nil is a pointer type that doesn't point to
anything}
   Write ('Press enter to continue...'); Readln;
End.



Wed, 18 Jun 1902 08:00:00 GMT  
 What is Pointer ?


:Could anyone explain, what a Pointer is,
:and how it does work ?

 93045 Jan 1 09:31 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
 tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

 320772 Oct 19 1992 ftp://garbo.uwasa.fi/pc/turbopas/tpr-book.zip
 tpr-book.zip Electronic Turbo Pascal Reference freeware book, E.Mitchell

 122618 Mar 18 1996 ftp://garbo.uwasa.fi/pc/turbopas/tptutr0h.zip
 tptutr0h.zip ASCII-text Turbo Pascal Tutor 1-20, G.Grotzinger, useful

"If you do not know how to go about getting this material, users are
welcome to email me for the prerecorded garbo.uwasa.fi instructions
(long, about 29Kb). If you do not receive my reply within five days,
please ask your own site's system manager to construct a returnable
mail path for you".

   All the best, Timo

....................................................................

Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa



Wed, 18 Jun 1902 08:00:00 GMT  
 What is Pointer ?

Quote:

>Could anyone explain, what a Pointer is,
>and how it does work ?

See URL below.

Glenn Grotzinger

MOD and S3M user extraordinaire.
Writer of TP tutorial.  All released parts findable at:
ftp://garbo.uwasa.fi/pc/turbopas/tptutr10.zip



Wed, 18 Jun 1902 08:00:00 GMT  
 What is Pointer ?

Quote:

>>Could anyone explain, what a Pointer is,
>>and how it does work ?
>See URL below.
>ftp://garbo.uwasa.fi/pc/turbopas/tptutr10.zip

Briefly, a pointer is a variable (4 bytes long) that contains an *address.*  
And it is normally used to refer, *indirectly*, to "whatever it is pointing
to."  

The only thing to remember about pointers is that you can refer to the pointer
itself, or to "the thing it is pointing to."  Let's use a concrete example:

    (1) At location 1,000 in memory there lives a pointer, "p."
    (2) At location 2,024 in memory is the variable "x" and at 3,600, the
        variable "y."
    (3) Let's do something like:   "p := Addr(x)".  Now "p" contains the value
        2,024.  And "p^" is understood to now be a reference to "whatever is
        to be found at location 2,024."  The computer first went to location
        1,000 ("p"), found the value 2,024 at that location, and went there to
        find the data "p^."
    (4) We can set "p := Addr(y)", and now "p^" magically refers to location
        3,600 and is synonymous with "y."

Pointers are most commonly used with "new" and "dispose."  These are used when
you decide on the spur-of-the-moment that you need to store something in
memory... the question becomes, "where can I put it?"  New() will decide where
you can put it, hand you back an address -- unknown to you until the moment
you made the call.  You put that address in a pointer-variable and now you can
reference the block of storage carved out for you by "new," by means of an
indirect reference to it through the pointer.  You always know where the
pointer lives; you don't know in advance what value it will contain...  2,024;
3,600; or something else.

/mr/



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Pointers - what am I missing?

2. Pointers: Am I an idiot ?

3. pointers, pointers, pointers...

4. Pointers Pointers Pointers

5. Pointers to pointers

6. Beginner needs some pointers with pointers!

7. POINTERS POINTERS...

8. DBLookupCombo - Documentation/Am I mad?

9. I am really sorry

10. What am I doing wrong...

11. I am stuck - TDecisionQuery AV in SQLORA8.DLL

12. WHAT DBGRID FIELD AM I

 

 
Powered by phpBB® Forum Software