Topics discussed in this section:

Slides:



Advertisements
Similar presentations
Week 8 Arrays Part 2 String & Pointer
Advertisements

An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
Topics discussed in this section:
General Computer Science for Engineers CISC 106 Lecture 34 Dr. John Cavazos Computer and Information Sciences 05/13/2009.
Parameter Passing to Functions in C. C Parameter passing Review of by-value/by-reference.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
Computer Science 210 Computer Organization Arrays.
Introduction to C++ Programming Language Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University,
1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C arrays ❏ To be able to pass arrays and array elements to functions.
Arrays.
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Arrays.
Array in C# Array in C# RIHS Arshad Khan
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Arrays Low level collections.
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Chapter 7 Part 1 Edited by JJ Shepherd
FIGURE 9-5 Integer Constants and Variables
Chapter 8 Arrays Objectives
Chapter 9 Pointers Objectives
C++ Arrays.
Using local variable without initialization is an error.
Topics discussed in this section:
CS 1430: Programming in C++.
C Passing arrays to a Function
Arrays, Part 1 of 2 Topics Definition of a Data Structure
2008/11/24: Lecture 19 CMSC 104, Section 0101 John Y. Park
Using Arrays in C Only fixed-length arrays can be initialized when they are defined. Variable length arrays must be initialized by inputting or assigning.
Building Java Programs Chapter 7
CS150 Introduction to Computer Science 1
2008/11/24: Lecture 19 CMSC 104, Section 0101 John Y. Park
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Topics discussed in this section:
Chapter 8 Arrays Objectives
Lecture 18 Arrays and Pointer Arithmetic
Topics discussed in this section:
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays .
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Cs212: Data Structures Computer Science Department Lecture 2: Arrays.
Pointers.
CS2011 Introduction to Programming I Arrays (I)
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Topics discussed in this section:
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CISC181 Introduction to Computer Science Dr
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Arrays ICS2O.
CS150 Introduction to Computer Science 1
Chapter 8 Arrays Objectives
CS149D Elements of Computer Science
CS150 Introduction to Computer Science 1
A Wide Array of Possibilities
Suggested self-checks: Section 7.11 #1-11
CS149D Elements of Computer Science
Pointers and dynamic objects
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Topics discussed in this section:
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Dry Run Fix it Write a program
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CSCE 206 Lab Structured Programming in C
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Presentation transcript:

Topics discussed in this section: 8-2 Using Arrays in C In this section, we first show how to declare and define arrays. Then we present several typical applications using arrays including reading values into arrays, accessing and exchanging elements in arrays, and printing arrays. Topics discussed in this section: Declaration and Definition Accessing Elements in Arrays Storing Values in Arrays Index Range Checking Computer Science: A Structured Programming Approach Using C

FIGURE 8-6 The Scores Array Computer Science: A Structured Programming Approach Using C

FIGURE 8-7 Declaring and Defining Arrays Computer Science: A Structured Programming Approach Using C

Note Only fixed-length arrays can be initialized when they are defined. Variable length arrays must be initialized by inputting or assigning the values. Computer Science: A Structured Programming Approach Using C

FIGURE 8-8 Initializing Arrays Computer Science: A Structured Programming Approach Using C

One array cannot be copied to another using assignment. Note One array cannot be copied to another using assignment. Computer Science: A Structured Programming Approach Using C

FIGURE 8-9 Exchanging Scores—the Wrong Way Computer Science: A Structured Programming Approach Using C

FIGURE 8-10 Exchanging Scores with Temporary Variable Computer Science: A Structured Programming Approach Using C

PROGRAM 8-2 Squares Array Computer Science: A Structured Programming Approach Using C

PROGRAM 8-2 Squares Array Computer Science: A Structured Programming Approach Using C

Topics discussed in this section: 8-3 Inter-function Communication To process arrays in a large program, we have to be able to pass them to functions. We can pass arrays in two ways: pass individual elements or pass the whole array. In this section we discuss first how to pass individual elements and then how to pass the whole array. Topics discussed in this section: Passing Individual Elements Passing the Whole Array Computer Science: A Structured Programming Approach Using C

FIGURE 8-11 Passing Array Elements Computer Science: A Structured Programming Approach Using C

FIGURE 8-12 Passing the Address of an Array Element Computer Science: A Structured Programming Approach Using C

void func( int farr[] ) { farr[0] = 1; { // main int arr[10]; int x; func(arr); } void func( int farr[] ) { farr[0] = 1; FIGURE 8-13 Passing an array Computer Science: A Structured Programming Approach Using C

Calculate Array Average PROGRAM 8-4 Calculate Array Average Computer Science: A Structured Programming Approach Using C

Calculate Array Average PROGRAM 8-4 Calculate Array Average Computer Science: A Structured Programming Approach Using C

Average Elements in Variable-length Array PROGRAM 8-5 Average Elements in Variable-length Array Don’t need * Computer Science: A Structured Programming Approach Using C

Average Elements in Variable-length Array PROGRAM 8-5 Average Elements in Variable-length Array Computer Science: A Structured Programming Approach Using C

Average Elements in Variable-length Array PROGRAM 8-5 Average Elements in Variable-length Array Don’t’ need size in parameter Computer Science: A Structured Programming Approach Using C

Average Elements in Variable-length Array PROGRAM 8-5 Average Elements in Variable-length Array Computer Science: A Structured Programming Approach Using C

Change Values in an Array PROGRAM 8-6 Change Values in an Array Computer Science: A Structured Programming Approach Using C

Change Values in an Array PROGRAM 8-6 Change Values in an Array Computer Science: A Structured Programming Approach Using C