Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and...

55
Young Won Lim 1/11/18 Pointers (1A)

Transcript of Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and...

Page 1: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Young Won Lim1/11/18

Pointers (1A)

Page 2: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Young Won Lim1/11/18

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 by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

Please send corrections (or suggestions) to [email protected].

This document was produced by using OpenOffice.

Page 3: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

3 Young Won Lim1/11/18

Address and Data in a Memory

0x000

1K x 8Memory

address 10 bits

dataaddress

data 8 bits

0x0010x0020x003

0x3FC0x3FD0x3FE0x3FF

210 = 1024

HEXaddress

8 bits10 bits

data

Page 4: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

4 Young Won Lim1/11/18

Variables

&a

data int a;

a can hold an integer a

address

&a

a = 100;

a holds an integer 100a 100

dataaddress

Page 5: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

5 Young Won Lim1/11/18

Pointer Variables

&p

int * p; *p holds an integer

pint * p;

pointer to int

int

int * p;

p holds an address

*p

p holds an addressof a int type data

p

Page 6: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

6 Young Won Lim1/11/18

Dereferencing

p

The content of a pointed location :Dereferencing operator *

*p

p

The address of a variable :Address of operator &

&

p

&p

*

p

*p

*

p

Page 7: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

7 Young Won Lim1/11/18

Variables and their addresses

&a

data

int a; a

address

int * p; &p p

Page 8: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

8 Young Won Lim1/11/18

Assignment of a variable

&a

data

int a; a = 111

address

int b; &b b = ____

Page 9: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

9 Young Won Lim1/11/18

Assignment of an address

&a

data

int a; a = 111

address

int * p; &p p = ____

Page 10: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

10 Young Won Lim1/11/18

Variables with initializations

&a

data

int a; a

address

int * p = &a; &p p = &a

Page 11: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

11 Young Won Lim1/11/18

Pointed addresses : p

p

data

int a; a

address

int * p = &a; p &p

p ≡ &a

Page 12: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

12 Young Won Lim1/11/18

Dereferenced Variable : *p

p

data

int a; *p

address

int * p = &a; p

*p ≡ a

&p

p ≡ &a*p ≡ a

Page 13: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

13 Young Won Lim1/11/18

Another way to access a : *p

*p =100 ≡ a = 100

&a

data

a

address

&p p

1) Read/Write a2) Read/Write *p

Page 14: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

14 Young Won Lim1/11/18

1. Pass by Reference2. Arrays

Page 15: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

15 Young Won Lim1/11/18

Pass by Reference

Page 16: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

16 Young Won Lim1/11/18

Variable Scopes

int main (){ int x, int y; ... ...

func1 ( 10, 20 );

... ...}

int func1 (int a, int b){ int i, int j; ... ...

... ...}

int x, int y;

int a, int b

int i, int j;

i and j’s variable scope

x and y’s variable scope

Only top stack frame is activeand its variable can be accessed

Communications are performed only through the parameter variables

( 10, 20 )

cannot access each other

func1’s Stack Frame

main’sStackFrame

xy

ab

Page 17: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

17 Young Won Lim1/11/18

Pass by Reference

int main (){ int x, int y; ... ...

func1 ( &x, &y );

... ...}

int func1 (int* a, int* b){ int i, int j; ... ...

... ...}

func1’s Stack Frame

main’sStackFrame int x, int y;

int* a, int* b

int i, int j;

x and y’s variable scope ( &x, &y )

x and y are made known to func1func1 can read / write x and ythrough their addresses

xy

ab

*a*b

a=&x b=&y

*a *b

Page 18: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

18 Young Won Lim1/11/18

Swapping integers

a = 111

b = 222

&a

&b

a = 222

b = 111

&a

&b

swap( &a, &b );

swap( int *, int *);

function call

function prototype

int a, b;

Page 19: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

19 Young Won Lim1/11/18

Pass by integer reference

void swap(int *p, int *q) {int tmp;

tmp = *p; *p = *q;

*q = tmp;}

int a, b;…

swap( &a, &b );

int * mint *m

int * nint *n

int tmp

Page 20: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

20 Young Won Lim1/11/18

Arrays

Page 21: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

21 Young Won Lim1/11/18

Accessing array elements – using an address

0

4

123

int x[5];

x holds the starting addressof 5 consecutive int variables

5 int variablesaddress data

x

x + 1

x + 2

x + 3

x + 4

*x

*(x+2)

*(x+4)

*(x+1)

*(x+3)

x[0]

x[4]

x[1]x[2]x[3]

index datacannot change address x (constant)

Page 22: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

22 Young Won Lim1/11/18

Accessing an Array with a Pointer Variable

int x [5] = { 1, 2, 3, 4, 5 };

int *p = x;

x[0]

x[4]

x[1] x[2] x[3]

60

904070

*(x+0)

*(x+4)

*(x+1) *(x+2) *(x+3)

p[0]

p[4]

p[1] p[2] p[3]

*(p+0)

*(p+4)

*(p+1) *(p+2) *(p+3)

x&x p&px is a constant symbol cannot be changed

p is a variable can point to other addresses

80

Page 23: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

23 Young Won Lim1/11/18

Pointer Type Cast

Page 24: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

24 Young Won Lim1/11/18

Integer Pointer Types

&a

data

long a;

address

int b;

short c;

&b

&c

char d; &d

a

b

c

d

Page 25: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

25 Young Won Lim1/11/18

Integer Pointer Types

data address

int *p;

short *q;

&p p

&q q

char *r; &r r

Page 26: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

26 Young Won Lim1/11/18

Byte Address

&a

data

long a;

address

LSByteaddress

MSByteaddress

Increasing address

Increasing address

Little Endian

Big Endian

a

Page 27: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

27 Young Won Lim1/11/18

Little Endian Byte Address Example

&a

data

long a;

address

LSB

yte

addre

ss

MSB

yte

addre

ss

Increasing address

a7 a6 a5 a4 a3 a2 a1 a0

0x3

00

7

0x3

00

6

0x3

00

5

0x3

00

4

0x3

00

3

0x3

00

2

0x3

00

1

0x3

00

0

Page 28: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

28 Young Won Lim1/11/18

Big Endian Byte Address Example

&a

data

long a;

address

LSB

yte

addre

ss

MSB

yte

addre

ss

Increasing address

0x3

00

0

0x3

00

1

0x3

00

2

0x3

00

3

0x3

00

4

0x3

00

5

0x3

00

6

0x3

00

7

a7 a6 a5 a4 a3 a2 a1 a0

&a

Page 29: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

29 Young Won Lim1/11/18

Representations of Endianness

0x3000

0x3001

0x3002

0x3003

0x3004

0x3005

0x3006

0x3007

a7

a6

a5

a4

a3

a2

a1

a0

0x3000

0x3001

0x3002

0x3003

0x3004

0x3005

0x3006

0x3007

a1

a2

a3

a4

a5

a6

a7

a0 0x3007

0x3006

0x3005

0x3004

0x3003

0x3002

0x3001

0x3000

a7

a6

a5

a4

a3

a2

a1

a0

0x3007

0x3006

0x3005

0x3004

0x3003

0x3002

0x3001

0x3000

a1

a2

a3

a4

a5

a6

a7

a0

Little Endian

Big Endian

Little Endian

Big Endian

&a &a

&a &a

https://stackoverflow.com/questions/15620673/which-bit-is-the-address-of-an-integer

Page 30: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

30 Young Won Lim1/11/18

Big Endian Byte Address Example

Processor Endianness

Motorola 68000 Big Endian

PowerPC (PPC) Big Endian

Sun Sparc Big Endian

IBM S/390 Big Endian

Intel x86 (32 bit) Little Endian

Intel x86_64 (64 bit) Little Endian

Dec VAX Little Endian

Alpha (Big/Little) Endian

ARM (Big/Little) Endian

IA-64 (64 bit) (Big/Little) Endian

MIPS (Big/Little) Endian

http://www.yolinux.com/TUTORIALS/Endian-Byte-Order.html

Page 31: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

31 Young Won Lim1/11/18

Byte Address

data address

0x3

00

7

0x3

00

6

0x3

00

5

0x3

00

4

0x3

00

3

0x3

00

2

0x3

00

1

0x3

00

0

int *p; pp+1

Page 32: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

32 Young Won Lim1/11/18

Byte Address

0x3

00

7

0x3

00

6

0x3

00

5

0x3

00

4

0x3

00

3

0x3

00

2

0x3

00

1

0x3

00

0

short *q; q+0q+2 q+1q+3

Page 33: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

33 Young Won Lim1/11/18

Byte Address

0x3

00

7

0x3

00

6

0x3

00

5

0x3

00

4

0x3

00

3

0x3

00

2

0x3

00

1

0x3

00

0

char *r;

r+7

r+6

r+5

r+4

r+3

r+2

r+1

r+0

Page 34: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

34 Young Won Lim1/11/18

Byte Address

0x3

00

7

0x3

00

6

0x3

00

5

0x3

00

4

0x3

00

3

0x3

00

2

0x3

00

1

0x3

00

0

int *p;

short *q;

char *r;

pp+1

qq+2 q+1p+3

Page 35: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

35 Young Won Lim1/11/18

Pointer Type Cast

data

long a;

int *p;

short *q;

p

q

char *r; r

p = (int *) &a

&a starting address

Page 36: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

36 Young Won Lim1/11/18

Integer Pointer Types

data

long a;

int *p;

short *q; q

char *r; r

p = (short *) &a

&a

Page 37: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

37 Young Won Lim1/11/18

Integer Pointer Types

data

long a;

int *p;

short *q;

char *r; r p = (char *) &a

&a

Page 38: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

38 Young Won Lim1/11/18

Re-interpretation of memory data

data

int a;

int *p;

short *q;

char *r;

&a

p = (short *) &a

p = (char *) &a

p = (int *) &a

Page 39: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

39 Young Won Lim1/11/18

const pointers

Page 40: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

40 Young Won Lim1/11/18

const type, const pointer type (1)

const int * p;

int * const q ;

const int * const r ;

Page 41: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

41 Young Won Lim1/11/18

const type, const pointer type (2)

qqp

integerinteger

read only

integerwr

read only

wr

const int * p; int * const q ;

address address

Page 42: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

42 Young Won Lim1/11/18

const type, const pointer type (3)

address

rr

read only

integerinteger

read only

const int * const r ;

wr

wr

Page 43: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

43 Young Won Lim1/11/18

Pointer Types and Associated Data

data

pc

char *pc;

data

ps

short *ps;

data

pi

int *pi;

short valchar val

int val

address address address

8 bits

incr

easi

ng a

ddre

ss

Page 44: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

44 Young Won Lim1/11/18

Pointer Types

data

pc

char *pc;

data

ps

short *ps;

data

pi

int *pi;

address address address

8 bits

incr

easi

ng a

ddre

ss

Page 45: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

45 Young Won Lim1/11/18

Little Endian Example

data

a

b

c int a;short b;char c;

&a

&b

&c

incr

easi

ng a

ddre

ss

8 bits

data

a

b

c

&a

&b

&c

8 bits

incr

easi

ng a

ddre

ss

the order of definition

Page 46: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

46 Young Won Lim1/11/18

int *, short *, char * type variables

int * pi;short * ps;char * pc;

pc

ps

pi

address

Not a sized representation

Page 47: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

47 Young Won Lim1/11/18

Pointer Variable Assignment

data

char * pc; short * ps;int * pi;

int a;short b;char c;

pc

ps

pi

pi = &a;ps = &b;pc = &c;

address

8 bits

a

b

c

&a

&b

&c

Page 48: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

48 Young Won Lim1/11/18

a

&a

a

&a

Pointer Type Casting

data

pc

char *pc;pc = (char *) &a

data

ps

data

pi

address address address

short *ps;ps = (short *) &a

int *pi;pi = (int *) &a

a

&a*ps

*pc

*pi

8 bits

Page 49: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

49 Young Won Lim1/11/18

Accessing bytes of a variable

data

pc

char *pc;pc = (char *) &a

address

a

&a

pc+3

pc+2

pc+1

pc

*(pc+3)

data

*(pc+2)

*(pc+1)

*(pc+0)

pc

char *pc;pc = (char *) &a

address

&a

pc+3

pc+2

pc+1

pc

8 bits

Page 50: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

50 Young Won Lim1/11/18

32-bit and 64-bit Address

32-bit machine : address : 4 bytes

64-bit machine : address : 8 bytes

pc

ps

pi

32-bit machine address :

4 bytes64-bit

machine address :

8 bytes

8 bits 8 bits

Page 51: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

51 Young Won Lim1/11/18

64-bit machine : 8-byte address

pi ps pc

char *pc; short *ps; int *pi;

Page 52: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

52 Young Won Lim1/11/18

64-bit machine : 8-byte address & data buses

char *pc; pc

8 bits

short *ps; ps

8 bits

int *pi; pi

8 bits

Page 53: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

53 Young Won Lim1/11/18

32-bit machine : 4-byte address

pi ps pc

char *pc; short *ps; int *pi;

Page 54: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

54 Young Won Lim1/11/18

64-bit machine : 8-byte address and data buses

char *pc;pc

8 bits

short *ps;ps

8 bits

int *pi;pi

8 bits

Page 55: Pointers (1A) - upload.wikimedia.org fileSeries: 2. Pointers 3 Young Won Lim 1/11/18 Address and Data in a Memory 0x000 1K x 8 Memory address 10 bits address data data 8 bits 0x001

Series:2. Pointers

55 Young Won Lim1/11/18

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 Express, I. K. Chun