{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# pointers - III.pointer arithmetic Adding a value to a...

This preview shows pages 1–2. Sign up to view the full content.

A pointer is a variable that stores the address of another variable =>Provides another way to re fu to a variable, through its address ratger tgab its symbolic name -Declaration int *p; Setting Pointers: int a, *p, *g; p = &a; g = p; // g has the same address of p Access through Pointers: int a, x, y, *p; p = &a; x = *p + y; // pointer dereference *p = x + y; Memory ---------- | | | | ---------- 0021303 | a | // a is a variable; we make the address p to indicate the location of a; ---------- | | | | ---------- 0021323 | p | // p is the location of a; but p also has a location 'int **p;' ---------- | | | | ---------- Printing Pointers: printf("%p", p); // print the thing stored in p

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: III .pointer arithmetic Adding a value to a pointer changes the pointer in increments of the sign of the element being pointed to: (e.g.) Int a, *p; Double b, *g; P = &a; P = P + 5; If &a = 0x100, then p = 0x100 + (4*5) = 0x114 //4 is for int, 4 bites G = &b; G = g+3; If &b = 0x200, then p = 0x200 + (8 *3) = 0x218 //8 is for double, 8 bites P++; => 0x114 + 4 = 0x118 G++; => 0x218 +8 = 0x220 *(a+i) = &a[i] IV. Pointers and Function Arguments Int main() { Int x = 5; Foo(x); } Void foo (int z) { Int y; Y = z + 10; Z = 7; } Int main() { Int x = 5; Foo(&x); } Void foo (int *z) //int * is pointer declaration { Int y; Y =* z + 10; Z = 7; }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

pointers - III.pointer arithmetic Adding a value to a...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online