UNIT II. -set of homogeneous data items. Eg: int arrays can hold only integers and char arrays can only hold characters. Arrays have a type, name, and.

Slides:



Advertisements
Similar presentations
UNIT IV.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Structure.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
Introduction to arrays Data in economy size packages.
Topic 9 – Introduction To Arrays. CISC105 – Topic 9 Introduction to Data Structures Thus far, we have seen “simple” data types. These refers to a single.
Programming with Collections Collections in Java Using Arrays Week 9.
Introduction to Computers and Programming Lecture 15: Arrays Professor: Evan Korth New York University.
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.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
1 ICS103 Programming in C Lecture 12: Arrays I. 2 Outline Motivation for One-dimensional Arrays What is a One-dimensional Array? Declaring One-dimensional.
Introduction of Arrays. Arrays Array form an important part of almost all programming language. It provides a powerful feature and can be used as such.
Arrays. Arrays  When a value is to be used in a program, a variable is declared to hold that value  What about storing the results of exams for a large.
Introduction to C Programming CE Lecture 9 Data Structures Arrays.
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
Pointers CS362. Pointers A Pointer is a variable that can hold a memory address Pointers can be used to: Indirectly reference existing variables (sometimes.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
COMP102 Lab 081 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
What is an Array? An array is a collection of variables. Arrays have three important properties: –group of related items(for example, temperature for.
Lecture 5: Arrays A way to organize data MIT AITI April 9th, 2005.
Spring 2005, Gülcihan Özdemir Dağ Lecture 7, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 7 Outline 7. 1.
Structures in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
Array, Structure and Union
19&20-2 Know how to declare pointer variables. Understand the & (address) and *(indirection) operators. Dynamic Memory Allocation Related Chapter: ABC.
CS 161 Introduction to Programming and Problem Solving Chapter 19 Single-Dimensional Arrays Herbert G. Mayer, PSU Status 10/8/2014 Initial content copied.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
C Programming – Part 3 Arrays and Strings.  Collection of variables of the same type  Individual array elements are identified by an integer index 
Computer Programming Lecture 8 Arrays. 2 switch-statement Example (3) If use press left arrowIf use press right arrow If use press up arrow If use press.
Introducing Arrays in C. PURPOSE: Storing multiple data items under the same name Example:  Salaries of 10 employees  Percentage of marks of my dear.
ICS103 Programming in C Lecture 11: Arrays I
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
CCSA 221 Programming in C CHAPTER 7 WORKING WITH ARRAYS 1.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
PHY281 Scientific Java Programming ArraysSlide 1 Arrays In this section we will learn how about storing groups of related variables that share the same.
UNIT-4 1. Arrays: Definition and declaration, Initialization, Accessing elements of arrays, Storing values in arrays, Inter-function Communication: Passing.
UNION UNIT -II. Unions A union is another compound datatype like a structure. So what is the properties of structure? Eg: Union exam { int roll_no; Char.
Computer Programming for Engineers
POINTERS IN C Pointer Basics, Pointer Arithmetic, Pointer to arrays and Pointer in functions.
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
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.
Arrays What is an array… –A data structure that holds a set of homogenous elements (of the same type) –Associate a set of numbers with a single variable.
Arrays C provides the option to the user to combine similar data types into a single entity It followed contiguous memory allocation.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Pointers: Basics. 2 Address vs. Value Each memory cell has an address associated with it
Windows Programming Lecture 03. Pointers and Arrays.
Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional Array Explain Arrays.
MAHENDRAN. Session Objectives Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional.
Array, Strings and Vectors
A simple way to organize data
Module 2 Arrays and strings – example programs.
DATA HANDLING.
Arrays C provides the option to the user to combine similar data types into a single entity It followed contiguous.
EKT150 : Computer Programming
Introduction To Programming Information Technology , 1’st Semester
Arrays in Java.
Arrays C provides the option to the user to combine similar data types into a single entity It followed contiguous.
Presentation transcript:

UNIT II

-set of homogeneous data items. Eg: int arrays can hold only integers and char arrays can only hold characters. Arrays have a type, name, and size. -share a common name. Eg: -Differentiated from one another by their positions. Eg: We refer to each item in an array as an element. The position of each element is known as its index. -Each array element is referred by specifying the array name, followed by a number(with square braces)as an index or subscript. Eg:

Array declarations similar to variables, but use square brackets: – datatype[] name; For example: – int[] prices; Can alternatively use the form: – datatype name[]; Eg: int prices[];

------Riddles

------Riddles Each morning I appear To lie at your feet, All day I will follow No matter how fast you run, Yet I nearly perish In the midday sun.

Unlike variables, we need to allocate memory to store arrays. (malloc() in C.) Use the new keyword to allocate memory: name = new type[size]; Eg: prices = new int[3];

Every element in an array is referenced by its index. If the array prices has size 3, its valid indices are 0, 1, and 2. Beware “Array out of Bounds” errors. Assigning variables: Example assigning values to each element of prices: prices[0] = 6; prices[1] = 80; prices[2] = 10;

We assign values to elements of String arrays in a similar fashion: string[] name; Eg: String[] people; people = new String[4]; people[0] = ”Alice”; people[1] = ”Bilha”; people[2] = ”Chris”; people[3] = ”David”;

You can also specify all of the items in an array at its creation. Eg: String[] people = {“Alice”, “Bilha”, “Chris”, “David”}; int[] prices = {6, 80, 10}; All the items must be of the same type. Array names used to identify the array.

Allocate - Create empty space that will contain the array. Initialize - Fill in a newly allocated array with initial values. Element - An item in the array. Index - Element’s position in the array. Size or Length - Number of elements.

My life can be measured in hours, I serve by being devoured. Thin, I am quick Fat, I am slow Wind is my foe. ?

I am seen in the water If seen in the sky, I am in the rainbow. ?

Two types of Array 1.Singly Dimensional Arrays. 2.Doubly Dimensional Arrays.

Initializing an array : ->during declaration. ->using loops. Initializing an array during declaration: -General form. Eg: int mark[7]={100,45,60,80,75}; char name[8]={`s`,`u`,`d`,`h`,`a`,`0`}; Syntax:? How mark array will get allocate? ->Implementation of Singly linked list.

Initializing an array : ->during declaration. ->using loops. Initializing an array using loops: -can be initialized by using for loop, a while loop or a do-while loop. -size should be a +ve integer constant, indicate the maximum no: can be stored. ->Implementation of Singly linked list.

Initializing an array using loops: -can be initialized by using for loop, a while loop or a do-while loop. -size should be a +ve integer constant, indicate the maximum no: can be stored. -In an n-element array, elements are stored in x[0],x[1],…………,x[n-2],x[n-1]. Eg: Fig:M/y allocation of a singly dimensional array. Eg: ->Implementation of Singly linked list.

-subscript specifies the elements ?? -array starts from?? Eg: Eg:for initializing an array using a for loop: 1) int i, mark[50]; 2)int i,mark[50],x=5; for(i=0;i<50;i++) for(i=0;i<50;i++) { mark[i]=0; mark[i]=x; } x+=5; o/p: ? } o/p:? ->Accessing array elements.

3)int i,mark[50]; for(i=0;i<50;i++) { scanf(“%d”,&mark[i]); } o/p: ? Similar for while and do while. ->Accessing array elements.

Riddles You heard me before, Yet you hear me again, Then I die, 'Till you call me again. ?

Two in a corner, 1 in a room, 0 in a house, but 1 in a shelter. What am I?

->Eg: int values[5]={21,5,79} -other space set to 0. ->Eg:int value[2]={4,3,5,6,7} -Error. ->not necessary to specify the length of an array. Eg: int value[]={5,4}; Eg: ->Rules for initializing an array

Eg: void main() { int a[5],sum=0,i; printf(“enter 5 integer number\n”); for(i=1;i<=5;i++) { scanf(“%d”,&a[i]); sum=sum+a[i]; } printf(“the sum of given no: %d\n”,sum); }

Elements are specified by 2 subscripts. i.e it requires two square brackets. ->used for matrix. Eg: Syntax: datatype arrayname[rowsize][columnsize]; Eg: To find total number of elements of a double dimensional array can be calculated from m*n n=column m=row Introduction of two dimensional array.

->Initializing an array during declaration. ->Initializing an array during using loops. Initializing an array during declaration: Eg: int mark [4][2]= { {85,56},{95,66}, {76,80},{50,90} }; 4-indicates? 2-indicates? or int mark[4][2]={85,56,95,66,76,80,50,90}; How it will allocate in m\y? Implementing double dimensional arrays.

Initializing an array during using loops. Eg: 1)int i,j,x=5,mark[10][5]; for(i=0;i<10;i++) { for(j=0;j<5;j++) { mark[i][j]=x; x+=5; } Implementing double dimensional array

Initializing an array during using loops. Eg: 2)int i,j,mark[10][5]; for(i=0;i<10;i++) { for(j=0;j<5;j++) { scanf(“%d”, &mark[i][j]; } Implementing double dimensional array

Arrays whose elements are specified by 3,4 subscripts or more said to be multidimensional arrays. Eg:?? Syntax of multidimensional array: ??? Eg:double dimensional matrix Introducing

#include void main() { int a[10][10],i,j,m,n,sum=0; printf(“enter the order of matrix:”); scanf(“%d %d”,&m,&n); printf(“enter the elements of matrix:”); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf(“%d”,&a[i][j]); } for(i=0;i<m;i++) { for (j=0;j<n;j++) { sum=sum+a[i][j]; } printf(“sum of elements of the matrix is %d”, sum); } Addition matrix Example

A structure is a collection of variables of same or different data types grouped together under a single name. Data items ->members of the structure. May contain one or more char,float,arrays,pointer… Uses: ->to organize data,particularly in large programs because they allow a group of related variables to be treated as a single unit.

Array ? Elements are referred by ? Members in a structure are referred by their unique name. Structure

Eg: struct emp { int empno; char empname[15]; float salary; }; Members? Structure name? So Syntax? Declaring a structure

If u break me, I do not stop working, If u touch me, I may be snared,If u lost me nothing will matter.

U saw me where I never was and where I could not be, And yet within that very place, my face u often see?

syntax struct { datatype member1; datatype member2; “ datatype membern; }structure _variable(s); struct emp { int empno; char empname[25]; float salary; }emp1; Eg:

From above example: Structure emp declares a variable ?. The structure_variables used to access the members of the structure. -more than one variable can be declared. Eg:?

A member of structure is referred and accessed by the structure variaable. Eg: ->The member access operator also referred as the dot operator “-” to access the member independently. Eg:emp1.empname; emp1.empno; Syntax: ? So emp1 is ?,used to access the members empname,empno using member access operator.

Eg emp1.empname=“Eve” To display the Value: Eg: puts(emp1.empname);

#include struct student { char name[10]; Int age; Int roll_no; }stud={“deepti”, 23, 938}; Void main() { printf(“\nName of student is %s”,stud.name); printf(“\nAge of student is %s”,stud.age); printf(“\nRoll no of student is %s”,stud.roll_no); } Output: Name of student is deepti Age of student is 23 Rollno of student is 938

I am always hungry, I must always be feed, the finger I touch will soon turn red.

I am a box that holds keys without locks,yet they can unlock ur souls.?