Program structure Four different storage-class specifications: –Automatic (auto): local to a function, normally declared variables are automatic. Does.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Chapter 7: Arrays In this chapter, you will learn about
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
 2006 Pearson Education, Inc. All rights reserved Arrays.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
C++ for Engineers and Scientists Third Edition
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
1 Arrays & functions Each element of an array acts just like an ordinary variable: Like any ordinary variable, you can pass a single array element to a.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Java Unit 9: Arrays Declaring and Processing Arrays.
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.
CSC – Java Programming II Lecture 9 January 30, 2002.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
CSEB114: PRINCIPLE OF PROGRAMMING Chapter 8: Arrays.
 2006 Pearson Education, Inc. All rights reserved Arrays.
18-2 Understand “Scope” of an Identifier Know the Storage Classes of variables and functions Related Chapter: ABC 5.10, 5.11.
A First Book of ANSI C Fourth Edition
6. More on Pointers 14 th September IIT Kanpur C Course, Programming club, Fall
Arrays- Part 2 Spring 2013Programming and Data Structure1.
Chapter 6 Arrays Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
18. DECLARATIONS.
Multi-Dimensional Arrays Arrays that have more than one index: Example of differences between basic data types and arrays using integers: Basic integer:
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
More Array Access Examples Here is an example showing array access logic: const int MAXSTUDENTS = 100; int Test[MAXSTUDENTS]; int numStudents = 0;... //
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Methods Awesomeness!!!. Methods Methods give a name to a section of code Methods give a name to a section of code Methods have a number of important uses.
Arrays.
Computer Programming for Engineers
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
+ Storage Classes and Linkage. + Introduction Scope describe the region or regions of a program that can access and identifier Variables can be shared.
Module 1: Array ITEI222 - Advance Programming Language.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
ADVANCED POINTERS. Overview Review on pointers and arrays Common troubles with pointers Multidimensional arrays Pointers as function arguments Functions.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
C++ for Engineers and Scientists Second Edition Chapter 12 Pointers.
Windows Programming Lecture 03. Pointers and Arrays.
Eine By: Avinash Reddy 09/29/2016.
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.
© 2016 Pearson Education, Ltd. All rights reserved.
Program to search an element of array using linear search.
JavaScript: Functions.
14th September IIT Kanpur
C Passing arrays to a Function
Arrays … The Sequel Applications and Extensions
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
7 Arrays.
CNG 140 C Programming (Lecture set 8)
Arrays Kingdom of Saudi Arabia
Introduction To Programming Information Technology , 1’st Semester
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Multidimensional array
Arrays Arrays A few types Structures of related data items
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.
C++ Array 1.
C Programming Lecture-17 Storage Classes
Presentation transcript:

Program structure Four different storage-class specifications: –Automatic (auto): local to a function, normally declared variables are automatic. Does not retain its value after exit from the function. –External (extern): Global variables. Same named local variables get precedence over global variables.

Program structure –Static (static): retain their values throughout the life of the program, but can be accessed only within the function. (I.e. fibonacci series) –Register (register)

Multifile programs An external function will be recognized throughout the entire program, whereas a static function will be recognized only within the file in which it is defined. First file extern void output(void); main() { output(); } Second file extern void output(void) { printf(“Hello World”); }

Multifile programs External variables can be defined in one file and accessed in another file. First file int a=1,b=2,c=3; Main() { … } Second File extern int a,b,c;

Array To represent multiple data items that have common characteristics All share the same name, but indices are different A one dimensional array definition may be expressed as storage-class data-type array[expression]; int x[100]; static char message[MAX];

Array definitions Array definitions can include the assignment of initial values if desired int digits[10]={1,2,3,4,5}; char color[3]={‘R’,’E’,’D’}; Array size need not be specified explicitly when initial values are included as part of an array definition. int digits[]={1,2,3,4,5};

Array declarations Following definitions are not same: char color[3]=“RED”;//size is 3,no \0 char color[]=“RED”;//size is 4,\0 included Arrays can be declared (because the array is defined elsewhere in the program) in the same manner as array definition except: –The square brackets may be empty –Initial values cannot be included

Array declaration example First file int c[]={1,2,3]; … Second file extern int c[]; …

Problems Store some in an array and fine the average of the numbers and deviation. Reverse a string Case conversion Reordering a list of numbers

Passing arrays to functions main() {int n; float list[100],avg; …. avg=average(n,list); …} float average(int a,float x[]) { } When a array is passed to a function, the values are not passed to the function. Rather array name is interpreted as the address of the 1 st array element. So the formal arg becomes a pointer.

Reordering a list of numbers Nested for loop Call reorder function and pass array as reference Call swap function and pass the values as reference Insertion and deletion of numbers Binary search

Multidimensional array float table[10][5];//a table of 10 rows and five columns int values[2][3]={1,2,3,4,5,6}; or int values[2][3]={{1,2,3}, {4,5,6}}; int values[2][3]={{1,2}, {3,4}}; int values[3][4]={1,2,3,4,5,6};

Problems Adding two tables of numbers Multiplying two matrices Store marks in a multidimensional array such that 10 students each having 5 courses and each course having 3 exams. Reordering a list of strings