LEC20081128 - Introduction to Computer Programming CSC180 Fall 2008 University of Toronto Review • Pointers and pointer arithmetic see pointer

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: Introduction to Computer Programming November 28, 2008 CSC180 Fall 2008, University of Toronto Review • Pointers and pointer arithmetic, see pointer arithmetic.pdf CSC180 Fall 2008, University of Toronto 1 Linked lists • A node: struct node { int data; struct node *next; struct node *prev; }; • Deletion: p->next->prev = p->prev; p->prev->next = p->next; free(p); CSC180 Fall 2008, University of Toronto 2 • Insertion: p->next = q->next; q->next->prev = p; q->next = p; p->prev = q; Or, p->next = q->next; p->prev = q; p->next->prev = p; p->prev->next = p; • Exercise: consider special cases for deletion and insertion. CSC180 Fall 2008, University of Toronto 3 Pass by value • Change variables of basic types #include <stdio.h> void clear(int n) { n = 0.0; } void clear2(int *n) { *n = 0.0; } int main() { CSC180 Fall 2008, University of Toronto 4 int x = 999; clear(x); printf("%d\n", x); clear2(&x); printf("%d\n", x); return 0; } • Change pointer variables #include <stdio.h> void clear(int *p) { p = NULL; } void clear2(int **p) CSC180 Fall 2008, University of Toronto 5 {...
View Full Document

This note was uploaded on 01/10/2011 for the course CSC 180 taught by Professor Na during the Fall '01 term at University of Toronto- Toronto.

Page1 / 12

LEC20081128 - Introduction to Computer Programming CSC180 Fall 2008 University of Toronto Review • Pointers and pointer arithmetic see pointer

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