lecture10 - Last time Introduction to Low-Level Programming...

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

View Full Document Right Arrow Icon
Introduction to Low-Level Programming Concepts CMSC 212 ecture 10 1 CMSC 212 Lecture 10 October 1, 2009 Last time Chapter 6, Pointers – the NULL pointer – pointer arithmetic – the relationship between arrays and pointers and examples of processing arrays with pointer arithmetic 2 CMSC 212 Reading Read Chapter 9 in Reek (Pointers on C) 3 CMSC 212 Chapter 6, Pointers, con't. 4 CMSC 212
Background image of page 1

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

View Full DocumentRight Arrow Icon
Are pointers and arrays the same thing? What will this program's output be? #include <stdio.h> int main() { char word1[]= "sesquipedalian"; char *word2= "sesquipedalian"; 5 CMSC 212 printf("%d\n", (int) sizeof(word1)); printf("%d\n", (int) sizeof(word2)); return 0; } Arrays of pointers What is the following? int *api[10]; Another example: char *ta_names[]= {"Mike", "Brandyn", 6 CMSC 212 "Daehwan", "Rachel"}; Compare this to the following: char ta_names[][8]= {"Mike", "Brandyn", "Daehwan", "Rachel"}; Generic ( void ) pointers A void pointer can point to any type oid ointer can't be ereferenced must first be void *p; int a= 2, *q= &a, *r; float b= 4.5; p= &a; p= &b; 7 CMSC 212 A void pointer can't be dereferenced- it must first be assigned or cast to a "real" pointer type p= q; /* "p= (void *) q" has the same effect, but is unnecessary */ printf("%d\n", *p); r= p; printf("%d", *r); printf("%d", *((int *) p)); printf("%d", (int) *p); Generic pointers, con't.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/23/2009 for the course CMSC 212 taught by Professor Staff during the Spring '08 term at Maryland.

Page1 / 5

lecture10 - Last time Introduction to Low-Level Programming...

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

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