{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec04

lec04 - Memory Model CS 2022 Introduction to C Instructor...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Memory Model CS 2022: Introduction to C Instructor: Hussam Abu-Libdeh Cornell University (based on slides by Saikat Guha) Fall 2009, Lecture 4 Memory Model CS 2022, Fall 2009, Lecture 4
Background image of page 1

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

View Full Document Right Arrow Icon
Pointers Recap I int *ptr; I Pointers are variables that store memory addresses of other variables I Type of variable pointed to depends on type of pointer: I int *ptr points to an integer variable, char *ptr points to character variable I Can cast between pointer types: my int ptr = (int *) my other ptr; I void *ptr has an unspecified type; must be cast to a type before used Memory Model CS 2022, Fall 2009, Lecture 4
Background image of page 2
Pointers Recap I Two main operaitons: I * dereference : get the value at the memory location stored in a pointer I & address of : get the address of a variable I int *my ptr = &my var; I Pointer arithmetic: directly manipulate a pointer’s content to access other locations I Use with caution! : can access bad areas of memory and cause a crash I However, it is useful in accessing and manipulating data structures I Can have pointers to pointers I int **my 2d array; Memory Model CS 2022, Fall 2009, Lecture 4
Background image of page 3

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

View Full Document Right Arrow Icon
Memory I Program code I Function variables I Arguments I Local variables I Return location I Global Variables I Statically Allocated I Dynamically Allocated Memory Model CS 2022, Fall 2009, Lecture 4
Background image of page 4
The Stack Stores I Function local variables I Temporary variables I Arguments for next function call I Where to return when function ends Memory Model CS 2022, Fall 2009, Lecture 4
Background image of page 5

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

View Full Document Right Arrow Icon
The Stack Managed by compiler I One stack frame each time function called I
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}