Pointers

Memory 0x0

0x1

0x2

0x3

0x4

0x5

0x6

0x7

0x8

0x9

0xA

0xB

Creating Pointers Declaring pointers: * Examples: int* x; char* y; float* z;

Referencing and Dereferencing

Referencing: & Dereferencing: *

Under the hood...

int x = 5; int* ptr = &x; int copy = *ptr;

Variable

Address

Value

x

0x04

5

ptr

0x08

0x04

copy

0x0C

5

Track the values

x

ptr

int x = 5;

5

int* ptr = &x;

5

&x

*ptr = 35;

35

&x

Test Yourself a 1. 2. 3. 4. 5. 6. 7.

b

c

pa pb pc

Answers int a = 3, b = 4, c = 5; int* pa = &a, *pb = &b, *pc = &c;

a

b

c

pa pb pc

a = b * c;

20

4

5

&a

&b

&c

a *= c;

100

4

5

&a

&b

&c

b = *pa;

100

100

5

&a

&b

&c

pc = pa;

100

100

5

&a

&b

&a

*pb = b * c;

100

500

5

&a

&b

&a

c = (*pa) * (*pc);

100

500

10000

&a

&b

&a

50000

500

10000

&a

&b

&a

*pc = a * (*pb);

Pointer Arithmetic Adding/subtracting n adjusts the pointer by n * sizeof() bytes x

y

int x = 5;

5

int* y = &x;

5

0x04

y += 1;

5

0x08

What will print? int main(void) { char* str = "happy cat"; int counter = 0; for (char* ptr = str; *ptr != '\0'; ptr++) { counter++; } printf("%d\n", counter); }

Pointers and Arrays

int array[3]; *array = 1; *(array + 1) = 2; *(array + 2) = 3;

0

1

1

2

2

3

Pointers

0x0. 0x1. 0x4. 0x5. 0x6. 0x9. 0x8. 0xA. 0xB. 0x2. 0x7. 0x3. Memory. Page 3. Page 4. Creating Pointers. Declaring pointers: ... What will print? int main(void). { char* str = "happy cat"; int counter = 0; for (char* ptr = str; *ptr != '\0'; ptr++). { counter++;. } printf("%d\n", counter);. } Page 12. Pointers and Arrays int array[3];. *array = 1;.

121KB Sizes 2 Downloads 216 Views

Recommend Documents

Pointers and Memory
18 classic linked list problems with solutions — a great way to practice with realistic, pointer intensive C code, ... How local variables and parameters work: local storage, allocation, deallocation, the ampersand bug. .... It turns out to be conv

Visual stability based on remapping of attention pointers
Object files: A temporary representation combining an object's identity, ..... target's feature data are to be found in earlier visual cortices which are shown, highly.

understanding pointers in c by yashwant kanetkar free pdf ...
Sign in. Page. 1. /. 1. Loading… Page 1 of 1. File: Understanding pointers in c by. yashwantkanetkar free pdf. Download now. Click here if your download doesn't ...

Collaborative Voting with Mice and Laser Pointers in ...
image using laser pointers in response to 3D demo videos. This interaction was ... In the software industry, such discussions ..... American Medical Informatics.

Make Pointers to Member Functions Callable -
auto p_fun = &non_member;. While the functions non_member() and member() have different rules for accessing members of X, on the call side, they're both still ...

Getting​​On​​The​​Air:​​​​Tips​​&​​Pointers Making ...
followed by either the phrase “monitoring” or “listening” or​​just​​simply​​say​​your​​call​​sign. “N7ACM​ ​Monitoring” or. “N7ACM​ ​Listening”.

pointers on c by kenneth reek free download pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. pointers on c by kenneth reek free download pdf. pointers on c by kenneth reek free download pdf. Open. Extr

A TUTORIAL ON POINTERS AND ARRAYS IN C by ...
Some computers, such as the IBM PC might require special handling to hold a ..... will be learning about pointers to structures and even pointer to pointers. ..... dimension the compiler would add 10*sizeof(int) which, on my machine, would be ...

Strategic Planning for ICASA - a few pointers from M ... -
The new timetable specifies that `the switch-on date of the broadcasting digital signal and the switch-off date of the analogue signal should be April 2012, and ...