CSC 172 DATA STRUCTURES.

Slides:



Advertisements
Similar presentations
Pointer Variables The normal variables hold values. For example, int j; j = 2; Then a reference to j in an expression will be identified with the value.
Advertisements

A pointer is the memory address of a variable. A memory address is a physical location within a system’s memory space. A pointer variable is variable used.
Data Structures (Second Part) Lecture 2 : Pointers Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
CSE 2501 Review Declaring a variable allocates space for the type of datum it is to store int x; // allocates space for an int int *px; // allocates space.
C language issues CSC 172 SPRING 2002 EXTRA LECTURE.
Weeks 5-6 Pointers and Arrays Basic pointer type Pointers and Arrays Address arithmetic Pointer Arrays User-defined data types Structures Unions Pointers.
POINTERS IN C Pointer Basics, Pointer Arithmetic, Pointer to arrays and Pointer in functions.
CSci 162 Lecture 6 Martin van Bommel. Functions on Structures Rather than pass a copy of structure to a function, or return a copy back as the function.
CSC 215 Pointers and Arrays. Pointers C provides two unary operators, & and *, for manipulating data using pointers The operator &, when applied to a.
THỰC TIỄN KINH DOANH TRONG CỘNG ĐỒNG KINH TẾ ASEAN –
BÖnh Parkinson PGS.TS.BS NGUYỄN TRỌNG HƯNG BỆNH VIỆN LÃO KHOA TRUNG ƯƠNG TRƯỜNG ĐẠI HỌC Y HÀ NỘI Bác Ninh 2013.
Evolving Architecture for Beyond the Standard Model
CMSC423: Bioinformatic Algorithms, Databases and Tools
Some aspect concerning the LMDZ dynamical core and its use
Bayesian Confidence Limits and Intervals
Front End Electronics for SOI Monolithic Pixel Sensor
Wavelet Coherence & Cross-Wavelet Transform
ლექცია 4 - ფული და ინფლაცია
10. predavanje Novac i financijski sustav
Particle acceleration during the gamma-ray flares of the Crab Nebular
Chapter 6 并发:死锁和饥饿 Operating Systems: Internals and Design Principles
Fairness-oriented Scheduling Support for Multicore Systems
Hui Wang†*, Canturk Isci‡, Lavanya Subramanian*,
Online Social Networks and Media
פרויקט מסכם לתואר בוגר במדעים (B.Sc.) במתמטיקה שימושית
Virtual Memory II CSE 351 Spring 2017
Topic 1 Applications of Physics
Machine learning tehniques for credit risk modeling in practice
Lower bounds against convex relaxations via statistical query complexity Based on: V. F., Will Perkins, Santosh Vempala. On the Complexity of Random Satisfiability.
The Seven Deadly Diseases
Chp9: ODE’s Numerical Solns
Liang Shang, Henan Normal University IHEP
Gravitation and Cosmology I Introduction to Cosmology
Emmanuel Mouche, Marie Alice Harel (LSCE)
On-Shell Methods in Quantum Field Theory
Use z-score as a standardized value for comparisons
Technologies Needed for Fusion DEMO and the Role of International Collaboration Mohamed Abdou Distinguished Professor of Engineering and Applied Science.
Hold and Sign: A Novel Behavioral Biometrics for Smartphone User Authentication Presented by: Dhruva Kumar Srinivasa Team-mate: Nagadeesh Nagaraja.
Chapter11 Authentication
Rural Investment and Policy Analysis (RIAPA) Modeling Toolkit
Which of these arrows is closest to your original guess?
The Rescorla-Wagner Learning Model (and one of its descendants)
APPLIED FLUID MECHANICS
Chemistry 200 Focus 1 Atoms.
Challenge ’16 The Answers.
IPM Simulations at Fermilab
Chapter 10. Cluster Analysis: Basic Concepts and Methods
Introduction to Data Science Lecture 4 Stats and Featurization
Sealed-Glass Proofs: What can we do with SGX without confidentiality?
ANTENNA FACTOR CALIBRATION TECHNIQUES
Warm-Up: March 4, 2016 Find the exact value of cos sin −1 − 4 5.
Department of Petroleum Engineering
for large surveys & censuses
Ethernet transport protocols for FPGA
Economic Growth and the Wealth of Nations
John Cowan Reuters Health Information
Introduction to metabolomics and data integration
Next Generation Carbon Nanotube Based Electronic Design
19. Inference about a population proportion
You must learn this for your GCSE
char first[10]="monkey"; char second[10]="fish"; char* keep;
INC 161 , CPE 100 Computer Programming
Basic notes on pointers in C
CSC 253 Lecture 8.
C Passing arrays to a Function
CSC 253 Lecture 8.
C Programming Pointers
Arrays and Pointers CSE 2031 Fall May 2019.
Arrays and Pointers CSE 2031 Fall July 2019.
Introduction to Pointers
Presentation transcript:

CSC 172 DATA STRUCTURES

POINTERS

POINTERS int a, b; a = 7; b = 11;

POINTERS int a, b; a = 7; b = 11; a 7 b 11

POINTERS int a, b; a = 7; b = 11; a 7 b 11 x01b5 xf37a

int a, b; a = 7; b = 11; &a ; //the address of a a 7 b 11 x01b5 xf37a

int *p ; //declaring a pointer p x0427 a 7 b 11 x01b5 xf37a

int *p p = &a ; p x01b5 x0427 a 7 b 11 x01b5 xf37a

int *p p = &a ; int c = *p ; 7 x015b 7 11 c p x219b x0427 a b x01b5 xf37a

Function Calls Call by value – you get a copy of the data

swap1 (x, y ) int x, y ; { int temp ; temp = x ; x = y; y = temp; } swap2 (px, py ) int *px, *py;{ int temp ; temp = *px ; *px = *py; *py = temp; }

COMPUTER MEMORY: A BIG ARRAY

ADDRESS CONTENT x[0] x0000 x[1] x0001 x[2] x0002 . . . . . .

. . . x[1] = 5; . . . ADDRESS CONTENT x[0] x0000 x[1] x0001 5

. . . x[3] = x[1]; . . . ADDRESS CONTENT x[0] x0000 x[1] x0001 5

. . . x[4] = &(x[1]); . . . ADDRESS CONTENT x[0] x0000 x[1] x0001 5

. . . x[6] = *(x[4]); . . . ADDRESS CONTENT x[0] x0000 x[1] x0001 5

int x = 1; int y = 2; int *ip ; int z[10];

. . . int x = 1; int y = 2; int *ip ; int z[10]; x0bc1 x0bc1 1 x0bc2 2

. . . int x = 1; int y = 2; int *ip ; int z[10]; x0bc1 x0bc1 1 x0bc2 1 ip = &x; y = *ip; . . .

. . . int x = 1; int y = 2; int *ip ; int z[10]; x0bc1 x0bc1 1 x0bc2 x0bc1 x0bc1 1 x0bc2 x0bc4 x0bc3 x0bc4 ip = &x; y = *ip; *ip = 0 ; ip = &z[10]; . . .

Arrays are pointers

ARRAYS ARE POINTERS int a[3], *p; a x01b5 p x01b6 xf37a x01b7

ARRAYS ARE POINTERS int a[3], *p; p = &a[0]; a p x01b5 x01b5 x01b6 xf37a x01b7

ARRAYS ARE POINTERS int a[3], *p; p = &a[0]; p = a; // same a p x01b5 xf37a x01b7

ARRAYS ARE POINTERS a[0] = 13; *p = 13; 13 a p x01b5 x01b5 x01b6 xf37a

ARRAYS ARE POINTERS a[1] = 29; *(p+1) = 29; 13 29 a p x01b5 x01b5 xf37a x01b7

ARRAYS ARE POINTERS a[2] = 31; *(p+2) = 31; 13 29 31 a p x01b5 x01b5 xf37a 31 x01b7

int k; for(k=0;k<3;k++){ a[k] = k * k; } for (k=0;k<3;k++) *(p+k) = k * k ;