{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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 Lecture 10 1 CMSC 212 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
Image of page 1

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

View Full Document Right 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", "Daehwan", 6 CMSC 212 "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 ° A void pointer can't be dereferenced- it must first be void *p; int a= 2, *q= &a, *r; float b= 4.5; p= &a; p= &b; 7 CMSC 212 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. ° A void pointer can be assigned to any "real" pointer type variable, and vice versa, without casting ° void pointers allow writing generic code, but you need to ensure that only appropriate things happen: double *dp; int i= 9, *ip= &i; 8 CMSC 212 ° NULL is defined as (void *) 0 void *p= ip;
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern