0% found this document useful (0 votes)
3 views

Pointers 3

Uploaded by

opensky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Pointers 3

Uploaded by

opensky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

This week

• Pointers
– Pointer Variable Declarations and Initialization
– Pointer Operators
– Pointers to void
– Calling Functions by Reference
– Passing parameters by reference
– sizeof function
– Dynamic Memory Management
– Pointer Arithmetic
– Pointers and Arrays
– Pointers to Functions
Variables Revisited
• What actually happens when we declare variables?
char a;

• C reserves a byte in memory to store a.

• Where is that memory? At an address.

• Under the hood, C has been keeping track of variables


and their addresses.

Slide credit: B. Huang


Pointers
• We can work with memory addresses too. We can
use variables called pointers.

• A pointer is a variable that contains the address of a


variable.

• Pointers provide a powerful and flexible method for


manipulating data in your programs; but they are
difficult to master.

– Close relationship with arrays and strings


Benefits of Pointers
• Pointers allow you to reference a large data structure in a
compact way.
• Pointers facilitate sharing data between different parts of
a program.
– Call-by-Reference
• Dynamic memory allocation: Pointers make it possible to
reserve new memory during program execution.

You might also like