Example passing the address of x x pint or

Slides:



Advertisements
Similar presentations
Numerical Recipes The Art of Scientific Computing (with some applications in computational physics)
Advertisements

For(int i = 1; i
Factorial Preparatory Exercise #include using namespace std; double fact(double); int fact(int); int main(void) { const int n=20; ofstream my_file("results.txt");
Passing by-value vs. by-reference in ARM by value C code equivalent assembly code int a;.section since a is not assigned an a:.skip initial.
CSC 270 – Survey of Programming Languages C Lecture 6 – Pointers and Dynamic Arrays Modified from Dr. Siegfried.
Review of Inheritance. 2 Several Levels of Inheritance Base Class B Derived class D Derived class D1.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Programming Languages and Paradigms The C Programming Language.
Tinaliah, S. Kom.. * * * * * * * * * * * * * * * * * #include using namespace std; void main () { for (int i = 1; i
Triana Elizabeth, S.Kom. #include using namespace std; void main () { for (int i = 1; i
Single Right rotation (compare to RotateWithLeftChild page 148 text) void rotateRight(AVLNode *& curr) { AVLNode * kid = curr->left; curr->left = kid->right;
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
1/03/09 De 89 à 98. 1/03/09 De 89 à 98 1/03/09 De 89 à 98.
C Pointers Systems Programming Concepts. PointersPointers  Pointers and Addresses  Pointers  Using Pointers in Call by Reference  Swap – A Pointer.
C Pointers Systems Programming. Systems Programming: Pointers 2 Systems Programming: 2 PointersPointers  Pointers and Addresses  Pointers  Using Pointers.
Functions Pass by Value Pass by Reference IC 210.
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);
17. ADVANCED USES OF POINTERS. Dynamic Storage Allocation Many programs require dynamic storage allocation: the ability to allocate storage as needed.
A way to pull together related data A Shape Class would contain the following data: x, y, height, width Then associate methods with that data A Shape.
7. Pointers, Dynamic Memory 20 th September IIT Kanpur 1C Course, Programming club, Fall 2008.
6. More on Pointers 14 th September IIT Kanpur C Course, Programming club, Fall
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
C Programming Day 4. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 More on Pointers Constant Pointers Two ways to.
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
CSC Programming for Science Lecture 36: Structures.
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Pointers.
One-dimensional arrays and strings: Chapter 6, Slide 1 The concept of array - an extension of the basic model of memory:
The This Pointer Programming in C++ Fall 2008 Dr. David A. Gaitros
1 2/2/05CS250 Introduction to Computer Science II Pointers.
Pointer Tran, Van Hoai. Pointers and Addresses  Pointer: group of cells (2,4 cells) Variable: group of cells Pointer is also a variable  Each cell (or.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
Pointers in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Pointers  * symbol and & symbol  Pointer operations  Pointer.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
C Lab 2 Intermediate Pointers & Basic Structures.
More on Functions. Assignment 1 Let’s talk … -We always validate to ensure that our program accepts only valid input. - This is done as early in the program.
。 33 投资环境 3 开阔视野 提升竞争力 。 3 嘉峪关市概况 。 3 。 3 嘉峪关是一座新兴的工业旅游城市,因关得名,因企设市,是长城文化与丝路文化交 汇点,是全国唯一一座以长城关隘命名的城市。嘉峪关关城位于祁连山、黑山之间。 1965 年建市,下辖雄关区、镜铁区、长城区, 全市总面积 2935.
Stack and Heap Memory Stack resident variables include:
Day 12 – September 11th Objective: To write an equations of a line given its slope and a point on the line  
Programming Languages and Paradigms
Pointers in C.
malloc(): Dynamic Memory Management
Learning Objectives Pointers Pointer in function call
Programming Paradigms
Yung-Hsiang Lu Purdue University
ASSIGNMENT NO.-2.
Programming Languages and Paradigms
14th September IIT Kanpur
Pointers and dynamic memory
Systems Programming Concepts
Return by Reference CSCE 121 J. Michael Moore.
Pointers & Functions.
Shaker.
class PrintOnetoTen { public static void main(String args[]) {
CS111 Computer Programming
Chien-Chung Shen CIS/UD
CISC181 Introduction to Computer Science Dr
7. Pointers, Dynamic Memory
C++ Pointers and Strings
C Programming Lecture-8 Pointers and Memory Management
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Pointers & Functions.
Unit-1 Introduction to Java
C Pointers Systems Programming.
pointer-to-pointer (double pointer)
Pointer Syntax Review *ptrName Declaring Pointers
Presentation transcript:

Example 1 125 100 100 passing the address of x x pint or int x = 100; sub1 (&x); void sub1 (int *pint) { *pint = *pint + 25; } passing the address of x x pint or de-referenced value of pint is the value of what pint points to pint &x

Example 2 125 passing the value of p which is the address of x 100 100 int x = 100; int *p = &x; sub1 (p); void sub1 (int *pint) { *pint = *pint + 25; } x pint p de-referenced value of pint is the value of what pint points to

Example 3 125 passing the address of p 100 100 x p ppint int x = 100; int *p = &x; sub2 (&p); void sub2 (int **ppint) { **ppint = **ppint + 25; } x p ppint double de-referenced value of ppint is the value of the value of what ppint points to

Example 4 100 x passing the address of p p ppint int x = 100; int *p = &x; sub2 (&p); void sub2 (int **ppint) { *ppint = malloc(sizeof(int)); **ppint = 50; } x passing the address of p p ppint single de-referenced value of ppint is the value of what ppint points to. In this case, we are assigning a value to what ppint points to. 50 double de-referenced value of ppint is the value of the value of what ppint points to malloc-ed

Example 5 100 x passing the address of p p ppint int x = 100; int *p = &x; sub2 (&p); void sub2 (int **ppint) { ppint = malloc(sizeof(int)); *ppint = 50; } x passing the address of p p ppint no de-referencing !! What is this changing? 50 single de-referenced value of ppint is the value of what ppint points to ppint itself malloc-ed