Applications of Pointers (1A) Young Won Lim 2/27/18

Size: px
Start display at page:

Download "Applications of Pointers (1A) Young Won Lim 2/27/18"

Transcription

1 Alications of (1A)

2 Coyright (c) Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A coy of the license is included in the section entitled "GNU Free Documentation License". Please send corrections (or suggestions) to youngwlim@hotmail.com. This document was roduced by using LibreOffice.

3 Variables and their es data int a; &a a int * ; & int **q; &q q 3

4 Initialized Variables data int a; &a a int * = &a; & = &a int **q = &; &q q = & 4

5 Pointed es :, q data int a; a int * = &a; q int **q = &; &q q = &a q = & 5

6 Dereferenced Variables : * data int a; * * a int * = &a; & int **q = &; &q q = &a q = & * = a 6

7 Dereferenced Variables : *q, **q data int a; *q **q **q a int * = &a; q *q *q int **q = &; &q q = &a q = & * = a *q = **q = a 7

8 Two more ways to access a : *, **q &a a * *q **q & & q *q &q q &q q &q q a * a **q a *q 8

9 Two more ways to access a : *, **q data &a a & * a **q a *q &q q 1) a 2) * 3) **q 9

10 Variables int a; a can hold an integer &a data a a = 100; a holds an integer 100 &a data a

11 Pointer Variables int * ; holds an int * ; holds an of a int tye data & ointer to int int * ; * holds an integer int * 11

12 Pointer to Pointer Variable int ** q; q holds an int ** q; ointer to ointer to int q holds an of a ointer to int tye data &q q int * *q; ointer to int *q holds an of a int tye variable q *q int **q; **q holds an integer *q **q int 12

13 Pointer Variables int a; &a 0x3A0 a data 200 int * = & a; & 0x3AB 0x3A0 int ** q = & ; &q 0x3CE q = 0x3AB &q 0x3CE q 0x3AB *q 0x3A0 **q

14 Pointer Variable * data &a 0x3A0 a data 200 & & 0x3AB 0x3A0 &q 0x3CE q = 0x3AB & * 0x3AB 0x3A

15 Pointer Variable q data data *q **q &a 0x3A0 a 200 q *q & 0x3AB 0x3A0 &q q &q 0x3CE q = 0x3AB &q q 0x3CE 0x3AB *q 0x3A0 **q

16 Interretation of Pointer (1) data **q data (int *) *q (int **) tye q Tyes Variables 16

17 Interretation of Pointer (2) **q data *q **q data *q q *q q &q q Variables Addresses 17

18 Integer Pointer Examles (1) int a; int * ; int ** q; a holds an integer (int *) holds an of a int tye value q holds an of a int ointer tye value (int **) (int *) 18

19 Integer Pointer Examles (2) int a ; int * ; int **q ; a * q q *q *q **q 19

20 Integer Pointer Examles (3) int a ; int * ; int * *q ; a * q q *q *q **q 20

21 Integer Pointer Examles (4) int a ; int * ; int ** q ; a * q q *q *q **q 21

22 Integer Pointer Examles (5) int a = 200; tyes int ** q &q q data = & int * = &a; int ** q = &; int * & i= &a int a &a a =200 *q = * = a *q = = &a **q = * = a 22

23 Integer Pointer Examles (6) int a; int * ; int ** q; (int **) X X (int *) (float *) (float) 23

24 Variable Declarations int a ; &a a =100 The variable a holds an integer data int * ; & 200 The ointer variable holds an, at this an integer is stored int * * q ; &q q 30 The ointer variable q holds an, where another is stored, where an integer data is stored 24

25 Access Data Via Pointer Variables (1) int a ; &a a =100 Direct Access &a value a integer int * ; & *=200 Indirect Access Dereference Oerator * the content of the ointed location & value *(&) * * integer 25

26 Access Data Via Pointer Variables (2) int * * q ; &q q q *q *q **q=30 Double Indirect Access &q value q Dereference Oerator * the content of the ointed location *(&q) *q q *q Dereference Oerator * the content of the ointed location *q **q *q **q integer 26

27 Access Data Via Pointer Variables (3) int a ; &a a =100 Direct Access &a value a integer int * ; & *=200 Indirect Access Dereference Oerator * the content of the ointed location value & * integer int * * q ; &q q q *q *q **q=30 Double Indirect Access Dereference Oerator * the content of the ointed location value &q q q *q *q **q integer 27

28 Access Data Via Pointer Variables (4) * int a &a a =100 *(&a) = a * * int * & *=200 *(&) = *() = * * * * int * * q &q q q *q *q **q=30 *(&q) = q *(q) = *q *(*q) = **q 28

29 Swaing ointers - ass by reference - double ointers 29

30 Swaing integer ointers & = &a & = &b &q q = &b &q q = &a a = 111 a = 111 b = 222 b =

31 Swaing integer ointers & = &a & = &b &q q = &b &q q = &a int *, *q; swa_ointers( &, &q ); swa_ointers( int **, int ** ); function call function rototye 31

32 Pass by integer ointer reference void swa_ointers (int **m, int **n) { int* tm; } tm = *m; *m = *n; *n = tm; int ** m int * *m int ** n int * *n int * tm int a, b; int *, *q; =&a, q=&b; swa_ointers( &, &q ); 32

33 Array of 33

34 Array of (1) int a [4]; int * b [4]; Array name a holds the starting int a [4] No. of elements = 4 Tye of each element Array name b holds the starting int * b [4] No. of elements = 4 Tye of each element 34

35 Array of (2) int a [4]; int * b [4]; a b b[0] *b[0] a[0] b[0] a[1] b[1] b[1] *b[1] a[2] b[2] a[3] b[3] b[2] *b[2] b[3] *b[3] 35

36 Array of (3) int a [4]; int * b [4]; (int *) (int * *) (int *) (int *) (int *) (int *) 36

37 2-d Arrays 37

38 A 2-D Array int c [4] [4]; c c[0] c[1] c[2] c[3] c[0] c[1] c[2] c[3] c[0][0] c[0][1] c[0][2] c[0][3] c[1][0] c[1][1] c[1][2] c[1][3] c[2][0] c[2][1] c[2][2] c[2][3] c[3][0] c[3][1] c[3][2] c[3][3] int c[4] [4] 38

39 A 2-D Array int c [4] [4]; (int * *) (int *) (int *) (int *) (int *) c[0] c[1] c[2] c[3] int c[4] [4] 39

40 A 2-D Array via a double ointer int c [4] [4]; (c [i])[j] (*(c+i))[j] *(*(c+i)+j) (c [I]) = (*(c+i)) (_)[j] = *((_)+j) int c[4] [4] 40

41 A 2-D Array int c [4] [4]; (int * *) (int *) (int *) (c+i) (int *) (int *) c[0] c[1] c[2] *(c+i)+j c[3] (c [i])[j] (*(c+i))[j] *(*(c+i)+j) 41

42 A 2-D array via a single ointer int c [4] [4]; c[0] c c[0] c[1] c[2] c[3] c[i][j] c[1] c[2] c[3] c[0][0] c[0][1] c[0][2] c[0][3] c[1][0] c[1][1] c[1][2] c[1][3] c[2][0] c[2][1] c[2][2] c[2][3] c[3][0] c[3][1] c[3][2] c[3][3] 0=[0*4+0] 1=[0*4+1] 2=[0*4+2] 3=[0*4+3] 4=[1*4+0] 5=[1*4+1] 6=[1*4+2] 7=[1*4+3] 8=[2*4+0] 9=[2*4+1] 10=[2*4+2] 11=[2*4+3] 12=[3*4+0] 13=[3*4+1] 14=[3*4+2] 15=[3*4+3] 42

43 A 2-D array via a single ointer int c [4] [4]; c[0] c c[0] c[1] c[2] c[3] c[i][j] c[1] c[2] c[3] [0*4+0] [0*4+1] [0*4+2] [0*4+3] [1*4+0] [1*4+1] [1*4+2] [1*4+3] [2*4+0] [2*4+1] [2*4+2] [2*4+3] [3*4+0] [3*4+1] [3*4+2] [3*4+3] int * =c[0]; [i*4+j] 43

44 2-D Array Dynamic Memory Allocation (1) int ** d ; d = (int **) malloc (4 * size of (int *)); for (i=0; i<4; ++i) d[i] = (int *) malloc(4 * sizeof); (int **) d (int *) (int *) (int *) (int *) d[0] d[1] d[2] d[3] 44

45 2-D Array Dynamic Memory Allocation (2) int ** d ; d = (int **) malloc (4 * size of (int *)); for (i=0; i<4; ++i) d[i] = (int *) malloc(4 * sizeof); &d (int **) d (int *) (int *) (int *) (int *) d[0] d[1] d[2] d[3] d[0][0] d[0][1] d[0][2] d[0][3] d[1][0] d[1][1] d[1][2] d[1][3] d[2][0] d[2][1] d[2][2] d[2][3] d[3][0] d[3][1] d[3][2] d[3][3] 45

46 Pointer to Arrays 46

47 Pointer to array (1) int a [4]; int a [4] (int []) a int (*) [4] ointer to the array of 4 elements a[0] a[1] a[2] a[3] int m ; an integer variable int *n ; a ointer variable int func (int a, int b) ; a rototye int (* f) (int a, int b) ; a function's tye int * f (int a, int b) ; function ointer 47

48 Pointer to array (2) int (*) [4] ; (int (*) []) int a [4] (int []) * a * = a (*) = a &(*) = &a = &a sizeof()= 4 bytes sizeof(*)= 16 bytes a[0] a[1] a[2] a[3] an array with 4 integer elements 48

49 Pointer to array (3) & int (*) [4] ; int c[4] [4] (int (*) []) = c (*) [ i ][ j ]; a 2-d array with 4 rows and 4 columns (int (*) []) (int []) (int []) (int []) (int []) c * c[0] c[1] c[2] c[3] *(+0) *(+1) *(+2) *(+3) c[0][0] c[0][1] c[0][2] c[0][3] c[1][0] c[1][1] c[1][2] c[1][3] c[2][0] c[2][1] c[2][2] c[2][3] c[3][0] c[3][1] c[3][2] c[3][3] 49

50 Pointer to array (4) int c [4][4]; int (*) [4]; = c; func(,... ); void func(int (*x)[4],... ) { } x[r][c] = void func(int x[ ][4],... ) { } x[r][c] = 50

51 References [1] Essential C, Nick Parlante [2] Efficient C Programming, Mark A. Weiss [3] C A Reference Manual, Samuel P. Harbison & Guy L. Steele Jr. [4] C Language Exress, I. K. Chun

Applications of Pointers (1A) Young Won Lim 3/14/18

Applications of Pointers (1A) Young Won Lim 3/14/18 (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished

More information

Applications of Pointers (1A) Young Won Lim 1/5/18

Applications of Pointers (1A) Young Won Lim 1/5/18 Alications of (1A) Coyright (c) 2010-2017 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Applications of Pointers (1A) Young Won Lim 3/21/18

Applications of Pointers (1A) Young Won Lim 3/21/18 (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished

More information

Applications of Pointers (1A) Young Won Lim 3/31/18

Applications of Pointers (1A) Young Won Lim 3/31/18 (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished

More information

Applications of Pointers (1A) Young Won Lim 4/11/18

Applications of Pointers (1A) Young Won Lim 4/11/18 (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished

More information

Pointers (1A) Young Won Lim 10/23/17

Pointers (1A) Young Won Lim 10/23/17 Pointers (1A) Coyright (c) 2010-2013 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Applications of Pointers (1A) Young Won Lim 4/24/18

Applications of Pointers (1A) Young Won Lim 4/24/18 (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished

More information

Pointers (1A) Young Won Lim 10/18/17

Pointers (1A) Young Won Lim 10/18/17 Pointers (1A) Coyright (c) 2010-2013 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Pointers (1A) Young Won Lim 12/4/17

Pointers (1A) Young Won Lim 12/4/17 Pointers (1A) Coyright (c) 2010-2017 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Pointers (1A) Young Won Lim 11/1/17

Pointers (1A) Young Won Lim 11/1/17 Pointers (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Applications of Pointers (1A) Young Won Lim 12/26/17

Applications of Pointers (1A) Young Won Lim 12/26/17 Applications of (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any

More information

Applications of Arrays (1A) Young Won Lim 2/11/17

Applications of Arrays (1A) Young Won Lim 2/11/17 Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information

Applications of Arrays (1A) Young Won Lim 3/15/17

Applications of Arrays (1A) Young Won Lim 3/15/17 Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information

Pointers (1A) Young Won Lim 1/9/18

Pointers (1A) Young Won Lim 1/9/18 Pointers (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Pointers (1A) Young Won Lim 1/5/18

Pointers (1A) Young Won Lim 1/5/18 Pointers (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Pointers (1A) Young Won Lim 3/5/18

Pointers (1A) Young Won Lim 3/5/18 Pointers (1A) Copyright (c) 2010-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Arrays (1A) Young Won Lim 12/4/17

Arrays (1A) Young Won Lim 12/4/17 Arrays (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Arrays (1A) Young Won Lim 1/27/17

Arrays (1A) Young Won Lim 1/27/17 Arrays (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Applications of Structures (1A) Young Won Lim 12/8/17

Applications of Structures (1A) Young Won Lim 12/8/17 Applications of (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any

More information

Overview (1A) Young Won Lim 9/14/17

Overview (1A) Young Won Lim 9/14/17 Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Overview (1A) Young Won Lim 9/9/17

Overview (1A) Young Won Lim 9/9/17 Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Applications of Structures (1A) Young Won Lim 12/4/17

Applications of Structures (1A) Young Won Lim 12/4/17 Applications of (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any

More information

Overview (1A) Young Won Lim 9/25/17

Overview (1A) Young Won Lim 9/25/17 Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Pointers (1A) Young Won Lim 1/14/18

Pointers (1A) Young Won Lim 1/14/18 Pointers (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Pointers (1A) Young Won Lim 1/22/18

Pointers (1A) Young Won Lim 1/22/18 Pointers (1A) Copyright (c) 2010-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Pointers (1A) Young Won Lim 2/6/18

Pointers (1A) Young Won Lim 2/6/18 Pointers (1A) Copyright (c) 2010-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Function Overview (1A) Young Won Lim 10/23/17

Function Overview (1A) Young Won Lim 10/23/17 Function Overview (1A) Copyright (c) 2010 2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or

More information

Pointers (1A) Young Won Lim 2/10/18

Pointers (1A) Young Won Lim 2/10/18 Pointers (1A) Copyright (c) 2010-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Type (1A) Young Won Lim 2/17/18

Type (1A) Young Won Lim 2/17/18 Type (1A) Copyright (c) 2010-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Memory Arrays (4H) Gate Level Design. Young Won Lim 3/15/16

Memory Arrays (4H) Gate Level Design. Young Won Lim 3/15/16 Arrays (4H) Gate Level Design Young Won Lim 3/15/16 Copyright (c) 2011, 2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation

More information

Structures (1A) Young Won Lim 12/4/17

Structures (1A) Young Won Lim 12/4/17 Structures (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Structure (1A) Young Won Lim 7/30/13

Structure (1A) Young Won Lim 7/30/13 Structure (1A) Copyright (c) 2010 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Applications of Array Pointers (1A) Young Won Lim 11/22/18

Applications of Array Pointers (1A) Young Won Lim 11/22/18 Appliations of Array Pointers (1A) Copyright () 2010-2018 Young W. Lim. Permission is granted to opy, distribute and/or modify this doument under the terms of the GNU Free Doumentation Liense, Version

More information

File (1A) Young Won Lim 11/25/16

File (1A) Young Won Lim 11/25/16 File (1A) Copyright (c) 2010-2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Variables (2D) Young Won Lim 3/28/18

Variables (2D) Young Won Lim 3/28/18 Variables (2D) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Structures (1A) Young Won Lim 11/8/16

Structures (1A) Young Won Lim 11/8/16 Structures (1A) Copyright (c) 2010-2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Arrays and Strings (2H) Young Won Lim 3/7/18

Arrays and Strings (2H) Young Won Lim 3/7/18 Arrays and Strings (2H) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or

More information

Number System (1A) Young Won Lim 7/7/10

Number System (1A) Young Won Lim 7/7/10 Number System (A) 7/7/ Copyrigt (c) 9-6 Young W. Lim. Permission is granted to copy, distribute and/or modify tis document under te terms of te GNU ree Documentation License, Version. or any later version

More information

Polymorphism (1A) Young Won Lim 8/22/13

Polymorphism (1A) Young Won Lim 8/22/13 Polymorhism (1A) Coyright (c) 2011-2012 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Polymorphism (1A) Young Won Lim 8/15/13

Polymorphism (1A) Young Won Lim 8/15/13 Polymorhism (1A) Coyright (c) 2011-2012 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Memory (1A) Young Won Lim 9/7/17

Memory (1A) Young Won Lim 9/7/17 (1A) Copyright (c) 21-26 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information

Pointers (2G) Young Won Lim 3/7/18

Pointers (2G) Young Won Lim 3/7/18 Pointers (2G) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Example 1. Young Won Lim 11/17/17

Example 1. Young Won Lim 11/17/17 Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information

Example 1 : using 1-d arrays. Young Won Lim 12/13/17

Example 1 : using 1-d arrays. Young Won Lim 12/13/17 : using 1-d arrays Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any

More information

Example 2. Young Won Lim 11/24/17

Example 2. Young Won Lim 11/24/17 Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information

Example 3 : using a structure array. Young Won Lim 11/25/17

Example 3 : using a structure array. Young Won Lim 11/25/17 : using a structure array Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

More information

ELF (1A) Young Won Lim 10/22/14

ELF (1A) Young Won Lim 10/22/14 ELF (1A) Copyright (c) 2010-2014 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Expressions (2E) Young Won Lim 3/10/18

Expressions (2E) Young Won Lim 3/10/18 Expressions (2E) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Lecture06: Pointers 4/1/2013

Lecture06: Pointers 4/1/2013 Lecture06: Pointers 4/1/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C 1 Pointers A ointer is a variable that contains the (memory) address of another variable What is a memory address?

More information

Expressions (2E) Young Won Lim 4/9/18

Expressions (2E) Young Won Lim 4/9/18 Expressions (2E) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Example 3. Young Won Lim 11/22/17

Example 3. Young Won Lim 11/22/17 Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information

Program Structure (2A) Young Won Lim 5/28/18

Program Structure (2A) Young Won Lim 5/28/18 Program Structure (2A) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or

More information

Program Structure (2A) Young Won Lim 3/8/18

Program Structure (2A) Young Won Lim 3/8/18 Program Structure (2A) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or

More information

ARM Assembly Exercise (1B) Young Won Lim 7/16/16

ARM Assembly Exercise (1B) Young Won Lim 7/16/16 ARM Assembly Exercise (1B) Copyright (c) 2014-2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

More information

Accessibility (1A) Young Won Lim 8/22/13

Accessibility (1A) Young Won Lim 8/22/13 Accessibility (1A) Copyright (c) 2011-2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any

More information

Class (1A) Young Won Lim 9/8/14

Class (1A) Young Won Lim 9/8/14 Class (1A) Copyright (c) 2011-2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Pointers and Memory Allocation p. 1. Brooklyn College. Michael Lampis. CISC 3130 Notes. Pointers and Memory Allocation

Pointers and Memory Allocation p. 1. Brooklyn College. Michael Lampis. CISC 3130 Notes. Pointers and Memory Allocation Pointers and Memory Allocation CISC 3130 Notes Michael Lamis mlamis@cs.ntua.gr Brooklyn College Pointers and Memory Allocation. 1 int x; Pointers x Pointers and Memory Allocation. 2 Pointers int x; int

More information

Algorithms Bubble Sort (1B) Young Won Lim 4/5/18

Algorithms Bubble Sort (1B) Young Won Lim 4/5/18 Algorithms Bubble Sort (1B) Young Won Lim 4/5/18 Copyright (c) 2017 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation

More information

Binary Search Tree (3A) Young Won Lim 6/2/18

Binary Search Tree (3A) Young Won Lim 6/2/18 Binary Search Tree (A) /2/1 Copyright (c) 2015-201 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

More information

Definition. Pointers. Outline. Why pointers? Definition. Memory Organization Overview. by Ziad Kobti. Definition. Pointers enable programmers to:

Definition. Pointers. Outline. Why pointers? Definition. Memory Organization Overview. by Ziad Kobti. Definition. Pointers enable programmers to: Pointers by Ziad Kobti Deinition When you declare a variable o any tye, say: int = ; The system will automatically allocated the required memory sace in a seciic location (tained by the system) to store

More information

Binary Search Tree (2A) Young Won Lim 5/17/18

Binary Search Tree (2A) Young Won Lim 5/17/18 Binary Search Tree (2A) Copyright (c) 2015-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or

More information

Structures (2I) Young Won Lim 4/17/18

Structures (2I) Young Won Lim 4/17/18 Structures (2I) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Class (1A) Young Won Lim 11/20/14

Class (1A) Young Won Lim 11/20/14 Class (1A) Copyright (c) 2011 2014 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Binary Search Tree (3A) Young Won Lim 6/4/18

Binary Search Tree (3A) Young Won Lim 6/4/18 Binary Search Tree (A) /4/1 Copyright (c) 2015-201 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

More information

Binary Search Tree (3A) Young Won Lim 6/6/18

Binary Search Tree (3A) Young Won Lim 6/6/18 Binary Search Tree (A) //1 Copyright (c) 2015-201 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

More information

Structures (2I) Young Won Lim 3/7/18

Structures (2I) Young Won Lim 3/7/18 Structures (2I) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

CMPE-013/L. Introduction to C Programming

CMPE-013/L. Introduction to C Programming CMPE-013/L Introduction to C Programming Gabriel Hugh Elkaim Winter 2015 and memory Pointer/array equivalency Pointer arithmetic and the stack and strings Arrays of ointers 1 Syntax tye *trname; How to

More information

Storage Allocation CSE 143. Pointers, Arrays, and Dynamic Storage Allocation. Pointer Variables. Pointers: Review. Pointers and Types

Storage Allocation CSE 143. Pointers, Arrays, and Dynamic Storage Allocation. Pointer Variables. Pointers: Review. Pointers and Types CSE 143 Pointers, Arrays, and Dynamic Storage Allocation [Chater 4,. 148-157, 172-177] Storage Allocation Storage (memory) is a linear array of cells (bytes) Objects of different tyes often reuire differing

More information

At this time we have all the pieces necessary to allocate memory for an array dynamically. Following our example, we allocate N integers as follows:

At this time we have all the pieces necessary to allocate memory for an array dynamically. Following our example, we allocate N integers as follows: Pointers and Arrays Part II We will continue with our discussion on the relationship between pointers and arrays, and in particular, discuss how arrays with dynamical length can be created at run-time

More information

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples:

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples: 1 Programming in C Pointer Variable A variable that stores a memory address Allows C programs to simulate call-by-reference Allows a programmer to create and manipulate dynamic data structures Must be

More information

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19 Access Young W. Lim 2017-06-10 Sat Young W. Lim Access 2017-06-10 Sat 1 / 19 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Data Movement Examples Young W. Lim Access 2017-06-10

More information

Day08 A. Young W. Lim Mon. Young W. Lim Day08 A Mon 1 / 27

Day08 A. Young W. Lim Mon. Young W. Lim Day08 A Mon 1 / 27 Day08 A Young W. Lim 2017-10-16 Mon Young W. Lim Day08 A 2017-10-16 Mon 1 / 27 Outline 1 Based on 2 C Functions (2) Storage Class and Scope Storage Class Specifiers A. Storage Duration B. Scope C. Linkage

More information

ELF (1A) Young Won Lim 3/24/16

ELF (1A) Young Won Lim 3/24/16 ELF (1A) Copyright (c) 21-216 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Eulerian Cycle (2A) Young Won Lim 4/26/18

Eulerian Cycle (2A) Young Won Lim 4/26/18 Eulerian Cycle (2A) Copyright (c) 2015 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any

More information

The Complexity of Algorithms (3A) Young Won Lim 4/3/18

The Complexity of Algorithms (3A) Young Won Lim 4/3/18 Copyright (c) 2015-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information

Functions (4A) Young Won Lim 5/8/17

Functions (4A) Young Won Lim 5/8/17 Functions (4A) Copyright (c) 2015 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Arrays. Young W. Lim Mon. Young W. Lim Arrays Mon 1 / 17

Arrays. Young W. Lim Mon. Young W. Lim Arrays Mon 1 / 17 Arrays Young W. Lim 2017-02-06 Mon Young W. Lim Arrays 2017-02-06 Mon 1 / 17 Outline 1 Introduction References Array Background Young W. Lim Arrays 2017-02-06 Mon 2 / 17 Based on "Self-service Linux: Mastering

More information

Functions (4A) Young Won Lim 3/16/18

Functions (4A) Young Won Lim 3/16/18 Functions (4A) Copyright (c) 2015 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

CS 1613 Lecture 24. Figure 1. Program p01.

CS 1613 Lecture 24. Figure 1. Program p01. Consider a rogram that is required to find all values larger than the average in a list of integers. The list is stored in a file. The rogram must read and store the list to fulfill its requirement. The

More information

Example: Runtime Memory Allocation: Example: Dynamical Memory Allocation: Some Comments: Allocate and free dynamic memory

Example: Runtime Memory Allocation: Example: Dynamical Memory Allocation: Some Comments: Allocate and free dynamic memory Runtime Memory Allocation: Examle: All external and static variables Global systemcontrol Suose we want to design a rogram for handling student information: tyedef struct { All dynamically allocated variables

More information

State Monad Example (3H) Young Won Lim 2/16/18

State Monad Example (3H) Young Won Lim 2/16/18 Copyright (c) 2016-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information

Arrays. Young W. Lim Wed. Young W. Lim Arrays Wed 1 / 19

Arrays. Young W. Lim Wed. Young W. Lim Arrays Wed 1 / 19 Arrays Young W. Lim 2017-02-08 Wed Young W. Lim Arrays 2017-02-08 Wed 1 / 19 Outline 1 Introduction References Array Background Young W. Lim Arrays 2017-02-08 Wed 2 / 19 Based on "Self-service Linux: Mastering

More information

a data type is Types

a data type is Types Pointers Class 2 a data type is Types Types a data type is a set of values a set of operations defined on those values in C++ (and most languages) there are two flavors of types primitive or fundamental

More information

[0569] p 0318 garbage

[0569] p 0318 garbage A Pointer is a variable which contains the address of another variable. Declaration syntax: Pointer_type *pointer_name; This declaration will create a pointer of the pointer_name which will point to the

More information

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18 Access Young W. Lim 2017-01-27 Fri Young W. Lim Access 2017-01-27 Fri 1 / 18 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Young W. Lim Access 2017-01-27 Fri 2 / 18 Based

More information

Algorithms Overview (1A) Young Won Lim 3/29/18

Algorithms Overview (1A) Young Won Lim 3/29/18 Algorithms Overview (1A) Copyright (c) 2017 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or

More information

Preprocessing (2K) Young Won Lim 3/7/18

Preprocessing (2K) Young Won Lim 3/7/18 Preprocessing (2K) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any

More information

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14 Day05 A Young W. Lim 2017-10-07 Sat Young W. Lim Day05 A 2017-10-07 Sat 1 / 14 Outline 1 Based on 2 Structured Programming (2) Conditions and Loops Conditional Statements Loop Statements Type Cast Young

More information

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018 CS 31: Intro to Systems Pointers and Memory Kevin Webb Swarthmore College October 2, 2018 Overview How to reference the location of a variable in memory Where variables are placed in memory How to make

More information

Pointers. Memory. void foo() { }//return

Pointers. Memory. void foo() { }//return Pointers Pointers Every location in memory has a unique number assigned to it called it s address A pointer is a variable that holds a memory address A pointer can be used to store an object or variable

More information

Structure (1A) Component

Structure (1A) Component Component Copyright (c) 2012 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Example: Pointer Basics

Example: Pointer Basics Example: Pointer Basics #include int (void) { float a1, a2; /* Simple variables */ float *p1, *p2, *w; /* Pointers to variables of type float */ a1 = 10.0, a2 = 20.0; printf("after a1 = 10.0;

More information

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology Introduction to C++ Massachusetts Institute of Technology ocw.mit.edu 6.096 Pointers 1 Background 1.1 Variables and Memory When you declare a variable, the computer associates the variable name with a

More information

RAM (1A) Young Won Lim 11/12/13

RAM (1A) Young Won Lim 11/12/13 RAM (1A) Young Won Lim 11/12/13 opyright (c) 2011-2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version

More information

(13-2) Dynamic Data Structures I H&K Chapter 13. Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University

(13-2) Dynamic Data Structures I H&K Chapter 13. Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University (13-2) Dynamic Data Structures I H&K Chapter 13 Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University Dynamic Data Structures (1) Structures that expand and contract

More information

Polymorphism Overview (1A) Young Won Lim 2/20/18

Polymorphism Overview (1A) Young Won Lim 2/20/18 Polymorphism Overview (1A) Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

More information

14. Memory API. Operating System: Three Easy Pieces

14. Memory API. Operating System: Three Easy Pieces 14. Memory API Oerating System: Three Easy Pieces 1 Memory API: malloc() #include void* malloc(size_t size) Allocate a memory region on the hea. w Argument size_t size : size of the memory block(in

More information

Background Functions (1C) Young Won Lim 4/3/18

Background Functions (1C) Young Won Lim 4/3/18 Background Functions (1C) Copright (c) 2016-2017 Young W. Lim. Permission is granted to cop, distribute and/or modif this document under the terms of the GNU Free Documentation License, Version 1.2 or

More information

Side Effects (3A) Young Won Lim 1/13/18

Side Effects (3A) Young Won Lim 1/13/18 Side Effects (3A) Copyright (c) 2016-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Monad Background (3A) Young Won Lim 11/20/17

Monad Background (3A) Young Won Lim 11/20/17 Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information