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

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 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 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 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 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 The Stack Managed by compiler I One stack frame each time function called I Created when function called I Stacked on top (under) one another I Destroyed at function exit Memory Model CS 2022, Fall 2009, Lecture 4 The Stack...
View Full Document

This document was uploaded on 03/10/2011.

Page1 / 32

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online