Pointers and Output Parameters. Pointers A pointer contains the address of another memory cell –i.e., it “points to” another variable 100.00 cost:1024.

Slides:



Advertisements
Similar presentations
C++ crash course Class 10 practice problems. Pointers The following function is trying to swap the contents of two variables. Why isnt it working? void.
Advertisements

Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
BBS514 Structured Programming (Yapısal Programlama)1 Pointers.
CPT: Pointers/ Computer Programming Techniques Semester 1, 1998 Objective of these slides: –to introduce pointer variables (pointers)
Pointers Discussion 5 Section Housekeeping HW 1 Issues Array Issues Exam 1 Questions? Submitting on Time!
1 CSE1301 Computer Programming Lecture 16 Pointers.
Pointers Ethan Cerami Fundamentals of Computer New York University.
Introduction to C Programming CE
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 9: Pass-by-Value.
1 ICS103 Programming in C Lecture 10: Functions II.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
1 CSE1301 Computer Programming Lecture 16 Pointers.
Pass by Reference. COMP104 Pass by Reference / Slide 2 Passing Parameters by Reference * To have a function with multiple outputs, we have to use pass.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
Pointers CSE 2451 Rong Shi.
ARRAYS In this Lecture, we will try to develop understanding of some of the relatively complex concepts. The following are explained in this lecture with.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
CP104 Introduction to Programming Modular Programming Lecture 16__ 1 Modular Programming II Functions with single output Functions with multiple outputs.
C++ function call by value The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter.
CSC 2400 Computer Systems I Lecture 5 Pointers and Arrays.
Passing Data - by Reference Syntax && double Pythagorus(double &, double &); Pythagorus(height, base); & & double Pythagorus(double& a, double& b) function.
Functions Pass by reference, or Call by reference Passing addresses Use of & part 3.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman Chapter 6 (Pointers) © CPCS
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
19&20-2 Know how to declare pointer variables. Understand the & (address) and *(indirection) operators. Dynamic Memory Allocation Related Chapter: ABC.
CSI1390 – Java Programming Methods II Instructor: Saeid Nourian
Lecture 6 C++ Programming Arne Kutzner Hanyang University / Seoul Korea.
Welcome to CISC220H Data Structures in C++ sakai.udel.edu Office Hours: Mon/Wed 3:30PM - 4:30PM TA: Adnan Ozsoy.
Pointers PART - 2. Pointers Pointers are variables that contain memory addresses as their values. A variable name directly references a value. A pointer.
142 L -1 Pointers Chapter 6 C uses a call BY VALUE for functions for example: void add_one(int x, int y) { x=x+1; y=y+1; } int main(void) { int a,b; a=4;
Introduction to Computing Lecture 12 Pointers Dr. Bekir KARLIK Yasar University Department of Computer Engineering
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT9: Pointer I CS2311 Computer Programming.
Pointers1 WHAT IS A POINTER? Simply stated, a pointer is an address. A running program consists of three parts: execution stack, code, and data. They are.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Welcome to CISC220 Data Structures in C++ sakai.udel.edu Office Hours: Tues 3PM - 4PM / Thurs 1PM - 2PM TA: David.
POINTERS IN C Pointer Basics, Pointer Arithmetic, Pointer to arrays and Pointer in functions.
FUNCTIONS (METHODS) Pascal C, C++ Java Scripting Languages Passing by value, reference Void and non-void return types.
Arrays. Example Write a program to keep track of all students’ scores on quiz 1. Need a list of everyone’s score Declare 14 double variables? What about.
C Programming Lecture 8 Call by Reference Scope. Call-by-Reference b For a C function to “effect” (read as “imitate”) call-by- reference: Pointers must.
CSE 220 – C Programming Pointers.
ICS103 Programming in C Lecture 10: Functions II
Pointers and Pass By Reference
EPSII 59:006 Spring 2004.
Pointers and Pointer-Based Strings
CSI-121 Structured Programming Language Lecture 16 Pointers
INC 161 , CPE 100 Computer Programming
Alternate Version of STARTING OUT WITH C++ 4th Edition
بنام خدا زبان برنامه نویسی C (21814( Lecture 11 Pointers
Subroutines – parameter passing
prepared by Senem Kumova Metin modified by İlker Korkmaz
CS2011 Introduction to Programming I Methods (II)
Dynamic Memory A whole heap of fun….
Simulating Reference Parameters in C
CSCE 206 Lab Structured Programming in C
C++ Pointers and Strings
C (and C++) Pointers April 4, 2019.
Pointers and References
Pointers and Pointer-Based Strings
C Programming Pointers
The Stack.
ICS103 Programming in C Lecture 10: Functions II
CSCE 206 Lab Structured Programming in C
Arrays and Pointers CSE 2031 Fall May 2019.
C++ Pointers and Strings
pointer-to-pointer (double pointer)
Arrays and Pointers CSE 2031 Fall July 2019.
ICS103 Programming in C Lecture 10: Functions II
Introduction to Pointers
Presentation transcript:

Pointers and Output Parameters

Pointers A pointer contains the address of another memory cell –i.e., it “points to” another variable cost:1024 cost_ptr:2048 double cost = ; double *cost_ptr = &cost;

Pointers A pointer contains the address of another memory cell –i.e., it “points to” another variable cost:1024 cost_ptr:2048 double cost = ; double *cost_ptr = &cost;

Pointers A pointer contains the address of another memory cell –i.e., it “points to” another variable cost:1024 cost_ptr:2048 double cost = ; double *cost_ptr = &cost; printf(“cost: %lf”, cost); printf(“cost_ptr: %d”, cost_ptr); printf(“&cost: %d”, &cost); printf(“&cost_ptr: %d”, &cost_ptr); printf(“*cost_ptr: %lf”, *cost_ptr);

Pointers A pointer contains the address of another memory cell –i.e., it “points to” another variable cost:1024 cost_ptr:2048 double cost = ; double *cost_ptr = &cost; cost: cost_ptr: 1024 &cost: 1024 &cost_ptr: 2048 *cost_ptr:

Call By Value int main(void) { int a = 5, b = 1; swap(a, b); printf(“a=%d, b=%d”, a, b); return (0); } void swap(int a, int b) { int tmp = a; a = b; b = tmp; printf(“a=%d, b=%d”, a, b); }

Call By Value int main(void) { int a = 5, b = 1; swap(a, b); printf(“a=%d, b=%d”, a, b); return (0); } void swap(int a, int b) { int tmp = a; a = b; b = tmp; printf(“a=%d, b=%d”, a, b); } Prints: a=1, b=5 a=5, b=1

Call By Value 5 a: b:1032 main swap 5 a: b: a: b:1024

Call By Reference 5 a: b:1032 main swap a:1028 b:1024

Call By Reference int main(void) { int a = 5, b = 1; swap(&a, &b); printf(“a=%d, b=%d”, a, b); return (0); } void swap(int *a, int *b) { int tmp = *a; //follow the pointer to a, get the value, and store it in tmp *a = *b; *b = tmp; printf(“a=%d, b=%d”, *a, *b); }

Call By Reference 1 a: b:1032 main swap a:1028 b:1024 a:1028 b:1024

fraction.c Create a single function that will multiply a fraction.