home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Learn Pascal in a Three Days (2nd Ed.)
(Publisher: Wordware Publishing, Inc.)
Author(s):
ISBN: 1556225679
Publication Date: 07/01/97

Bookmark It

Search this book:
 
Previous Table of Contents Next


Sample run:

In the following run, option "1" was chosen in order to add a new employee (SSN: 222-22-2222). The program, however, refused to add it because the "SearchList" procedure found this "SSN" in the list.

------------- Main Menu --------------
1. Add records to the list.
2. Display the whole list.
3. Display an employee record.
4. Add records from file.
5. Save the list to a file.
6. Delete a record.
7. Update a record.
8. Exit.
--------------------------------------
Make a choice and press a number: 4
The employee list is ready in memory.
Hit any key to continue...
------------- Main Menu --------------
1. Add records to the list.
2. Display the whole list.
3. Display an employee record.
4. Add records from file.
5. Save the list to a file.
6. Delete a record.
7. Update a record.
8. Exit.
--------------------------------------
Make a choice and press a number: 1
Please enter the SSN of the employee: 222-22-2222
The SSN: 222-22-2222 is already in the list.
Hit any key to continue...

Summary

In this chapter you learned the following features of pointers:

1.  A pointer may be used to point to any data type.
2.  A pointer to a specific data type is bound to this type.
3.  You cannot read or display the value of a pointer. You can only read or display the value pointed to by the pointer.
4.  The operations you may apply on pointers are assignment and comparison (= or <>). The only values you may assign to a pointer are the constant NIL or the value of another pointer bound to the same type.
5.  To declare a pointer type use the general form:
          TYPE
              Pointer-Type = ^ type-definition;

where “type-definition” is a standard or user-defined type.
6.  The procedure NEW is used to allocate memory for a pointer, while the procedure DISPOSE is used to release the allocated memory. The two procedures use the pointer as a parameter:
NEW(PtrVariable);
DISPOSE(PtrVariable);

You also learned how to use linked lists as advanced data structures that expand or shrink dynamically during the execution of the program. The following are the most important features of linked lists:

1.  In a linked list, data are stored in nodes. Each node contains a data-field and a pointer-field. The pointer-field points to the second node.
2.  The nodes in a linked list may store any type of data, however, they are used most often to store records.
3.  To declare a linked list use the general form:
           TYPE
               Data-Type = type-definition;
               ListPointer = ^ListRecord;
               ListRecord = RECORD
                     DataField :Data-Type;
                     NextField :ListPointer;
               END
4.  Linked lists are constructed and manipulated using pointers.
5.  You may add or delete nodes to or from a linked list. Nodes can only be added at the beginning of the list.

The Next Step

By the end of this chapter you have enough tools to practice programming in Pascal and create good application programs. However, you may want to read about some topics which are not covered in this book:

  Direct/random access files
  Graphics

These topics are not included in standard Pascal, so you have to refer to books on your specific compiler.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.