ㅎㅎ Fourth step for Learning C++ Programming Call by value

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
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.
CISC Data Structures Ben Perry University of Delaware Summer 2011.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
The simple built-in data types of the C language such as int, float, - are not sufficient to represent complex data such as lists, tables, vectors, and.
Programming and Data Structure
Introduction to Programming Lecture 39. Copy Constructor.
CS 106 Introduction to Computer Science I 02 / 29 / 2008 Instructor: Michael Eckmann.
C++ Spring 2000 Arrays1 C++ Arrays. C++ Spring 2000 Arrays2 C++ Arrays An array is a consecutive group of memory locations. Each group is called an element.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
Multiple-Subscripted Array
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Pointers CSE 2451 Rong Shi.
C Static Arrays Pepper. What is an array? Memory locations – same type – next to each other (contiguous) – Same name – Indexed by position number of type.
Arrays- Part 2 Spring 2013Programming and Data Structure1.
Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.
Lecture 7 Introduction to Programming in C Arne Kutzner Hanyang University / Seoul Korea.
1 ร. ศ. ดร. สุเทพ มาดารัศมี Understanding Pointers in C Chapter 10 of Programming with C Book.
Pointers *, &, array similarities, functions, sizeof.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
Engineering Computing I Chapter 5 Pointers and Arrays.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
C++ Arrays SarMag Trimester 31 C++ Arrays. C++ Arrays SarMag Trimester 32 C++ Arrays An array is a consecutive group of memory locations. Each group is.
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.
Windows Programming Lecture 03. Pointers and Arrays.
Data Storage So far variables have been able to store only one value at a time. What do you do if you have many similar values that all need to be stored?
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline 1 Introduction 2 Arrays 3Declaring Arrays 4Processing Array Contents 5 Multiple-Subscripted.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Arrays in C. What is Array? The variables we have used so far can store a single value. Array is a new type of variable capable of storing many values.
char first[10]="monkey"; char second[10]="fish"; char* keep;
Chapter 6 Arrays in C++ 2nd Semester King Saud University
Arrays Low level collections.
An Introduction to Programming with C++ Sixth Edition
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.
Documentation Need to have documentation in all programs
Fifth Lecture Arrays and Lists
CS1010 Discussion Group 11 Week 7 – Two dimensional arrays.
New Structure Recall “average.cpp” program
Chapter 8 Arrays Objectives
Object-Oriented Programming Using C++
Sorting Data are arranged according to their values.
The University of Texas – Pan American
Basic notes on pointers in C
ㅎㅎ Fourth step for Learning C++ Programming Two functions
5. Arrays, Pointers and Strings
7 Arrays.
بنام خدا زبان برنامه نویسی C (21814( Lecture 11 Pointers
Chapter 8 Arrays Objectives
Lecture 18 Arrays and Pointer Arithmetic
Sorting Data are arranged according to their values.
Review of Arrays and Pointers
Functions with arrays.
CSE 100 Data Types Declarations Displays.
MSIS 655 Advanced Business Applications Programming
Given value and sorted array, find index.
7 Arrays.
C++ Pointers and Strings
To refer to an element, specify
§ § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊
Chapter 8 Arrays Objectives
C++ winter2008(by:J.Razjouyan)
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.
Peer Instruction 4 Control Loops.
C++ Pointers and Strings
§ § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays – Exercises UTPA – Fall 2012 This set of slides is revised from lecture slides of Prof.
Presentation transcript:

ㅎㅎ Fourth step for Learning C++ Programming Call by value Call by reference Array 2-D Array Array Searching Bubble-Sort Binary-Search

Call-by-value vs Call-by-reference So far we looked at functions that get a copy of what the caller passed in. - This is call-by-value, as the value is what gets passed in (the value of a variable). We can also define functions that are passed a reference to a variable. - This is call-by-reference, the function can change a callers variables directly.

Call-by-value vs Call-by-reference A reference variable is an alternative name for a variable. A shortcut. A reference variable must be initialized to reference another variable. Once the reference is initialized you can treat it just like any other variable.

[ Practice 1 - defining and using a reference ] [ex 1]

[ Practice 1 - defining and using a reference ] [ex 1] & is not the address operator as part of the type identifier & is the address operator &rodents representing the address of the variable to which rodents refers

[ Practice 2 - defining and using a reference ] [ex 2]

[ Practice 3 – Swap ] [ex 3]

An array is a sequence of consecutive memory elements. C++ Arrays An array is a sequence of consecutive memory elements. The contents of all elements are of the same type. Could be an array of int, double, char, … We can refer to individual elements by giving the position number (index) of the element in the array. 10/2014

int foo[6]; Each int is 4 bytes foo[0] foo[1] foo[5] 4 bytes Memory and Arrays 4 bytes Each int is 4 bytes foo[0] foo[1] int foo[6]; foo[5] 10/2014

foo[17], foo[i+3], foo[a+b+c] C++ Arrays The first element is the 0th element! If you declare an array of n elements, the last one is number n-1. If you try to access element number n it is an error! The element numbers are called subscripts: foo[i] A subscript can be any integer expression: These are all valid subscripts: foo[17], foo[i+3], foo[a+b+c] 10/2014

Initialization Rules for Arrays 1. int cards[4] = {3, 6, 8, 10}; //valid 2. int hand[4] = {}; 3. hand[4]; //invalid 4. float hotelTips[5] = {5.0, 2.5}; //valid - hotelTips[0] = 5.0, - hotelTips[1] = 2.5 5. long totals[500] = {0}; 6. short things[] = {1, 5, 3, 8}; Ο Ο X O Ο Ο

[ Practice 4 - Array ]

[ Practice 4 - Array ] index→ 0 1 2 index → 0 1 2

[ Practice 5 - Array 2 ]

[ Practice 5 - Array 2 ]

2-D Array: int A[3][4] Col 0 Col 1 Col 2 Col 3 Row 0 A[0][0] A[0][1] 10/2014

2-D Array: char A[4][3] Memory Organization { A[0][0] A[0][1] A[0][2] A[1][0] A[1][1] A[1][2] A[2][0] A[2][1] A[2][2] A[3][0] A[3][1] A[3][2] A[0] A[1] A[2] A[3] char A[4][3]; { A is an array of size 4. Each element of A is an array of 3 chars { { 10/2014

[ Practice 6 - 2-D Array ]

[ Practice 6 - 2-D Array ]

[ Practice 7 - Array Searching ]

Bubble-Sort 10/2014

[ Practice 8 - Bubble Sort ]

Binary Search

Exercise

Result