Complex data types Complex data types: a data type made of a complex of smaller pieces. Pascal has four very commonly used complex data types: strings,

Slides:



Advertisements
Similar presentations
UNIT IV.
Advertisements

Introduction to C Programming
Structure.
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
Chapter 7 Introduction to Arrays Part I Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Simple Arrays Programming COMP104 Lecture 12 / Slide 2 Arrays l An array is a collection of data elements that are of the same type (e.g., a collection.
Pascal Programming Pascal Units, Abstract Data, Ordinals, Arrays.
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
CSC 107 – Programming For Science. Today’s Goal Variables  Variable  Variable name location to store data  Only for humans; 0 x 7E8A2410 harder to.
COMP102 Lab 081 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
Arrays Arrays in C++ An array is a data structure which allows a collective name to be given to a group of elements which all have.
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
Pascal Programming Arrays and String Type.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
Arrays An array is an indexed data structure which is used to store data elements of the same data type. An array is an indexed data structure which is.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Grouping Data Together Often we want to group together a number of values or objects to be treated in the same way e.g. names of students in a tutorial.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Fall 2001(c)opyright Brent M. Dingle 2001 Abstract Data Types (ADTs) Brent M. Dingle Texas A&M University Chapter 8 – Sections 2 and 3 (and some from Mastering.
Lecture 5 array declaration and instantiation array reference
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Chapter VII: Arrays.
Pointers What is the data type of pointer variables?
Pascal Programming Arrays and String Type.
Test 2 Review Outline.
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
The CONST definition CONST Pi = , City = ‘New York’;
© 2016 Pearson Education, Ltd. All rights reserved.
Arrays Arrays exist in almost every computer language.
Arrays (in Small Basic)
Arrays Declarations CSCI N305
Lecture-5 Arrays.
JavaScript: Functions.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Data Types and Expressions
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
Array Data Structure Chapter 6
CMPE 152: Compiler Design September 18 Class Meeting
7 Arrays.
Array Data Structure B.Ramamurthy 11/21/2018 B.Ramamurthy.
Pointers and Pointer-Based Strings
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Introduction To Programming Information Technology , 1’st Semester
JavaScript Arrays.
Arrays ICS2O.
Arrays Chapter 8 Copyright © 2008 W. W. Norton & Company.
MSIS 655 Advanced Business Applications Programming
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Fundamental Programming
Arrays An array is a grouping of elements of the same type that share a common base name Can have any number of elements in the array Individual elements.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Dr Tripty Singh Arrays.
CSC 142 Arrays [Reading: chapter 12].
Chapter 9: Data Structures: Arrays
Array Data Structure Chapter 6
JavaScript: Arrays.
Arrays Arrays A few types Structures of related data items
C Programming Pointers
Course Overview PART I: overview material PART II: inside a compiler
CS150 Introduction to Computer Science 1
C Data Types and Variable
Arrays.
C++ Array 1.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Casting & User Defined Variables
Arrays Prepared By Paritosh Srivastava PGT (CS) KV NHPC Banbasa.
ㅎㅎ Fourth step for Learning C++ Programming Call by value
Array Fundamentals A simple example program will serve to introduce arrays. This program, REPLAY, creates an array of four integers representing the ages.
4.1 Introduction Arrays A few types Structures of related data items
Presentation transcript:

Complex data types Complex data types: a data type made of a complex of smaller pieces. Pascal has four very commonly used complex data types: strings, array, records and objects. We have already covered strings, will cover arrays in the next few classes and will not cover records or objects.

TYPE The reserved word TYPE introduces new types in Pascal. One new type you can define is an array. The format of an array type definition is: TYPE IntArray = ARRAY[1..5] OF integer; This definition would produce a new type ‘IntArray’ which would consist of an array of memory locations (5 of them) which store integers.

TYPE IntArray = ARRAY[1..5] OF integer; TYPE: tells compiler we are defining a new type IntArray: The name of the new type (name must conform to rules for naming an identifier) ARRAY: tells compiler the new type will be an array [1..5]: 1 will be lowest subscript; 5 will be highest. Both numbers must be same ordinal type. (Called dimensioning an array) OF integer: means the array will store values of type integer (an array can only store one type).

Once a new type is defined, you can declare a variable to hold the type like you do for a simple type. For example: VAR MyArray, YourArray: IntArray; would create two new identifiers (MyArray and YourArray) both of type IntArray. Each identifier can now hold 5 integers.

How do we access the values? To access the first value of MyArray, we would write: MyArray[1] This would be used as any other simple variable would be used. The 1 between the brackets is called a subscript (or index).

How do we access the values (con’t) You can also use variables or complex expressions as subscripts. For Example: MyArray[X] or MyArray[X+2] or MyArray[MyArray[2]] This makes the array data type very powerful

Out-of-range error An out-of-range error is when you try to access an element of an array that is outside the range indicated in the declaration. When using arrays, the compiler may not pick up on an out-of-range error.

Difference between TYPE and VAR TYPE declares a new type that you can use in the VAR section. VAR declares a new variable of a certain type. It can be a predefined type (integer, char, etc.) or a user defined type (MyArray)

Placement of type definition In Turbo Pascal, the TYPE definition can be placed before or after the CONST definition and the VAR declaration unless an item in one of these depends on a definition in the others. CONST MaxSubscr = 20; TYPE IntArray = ARRAY [1..MaxSubsc] OF integer; VAR MarkArray: IntArray;