{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture11slides

# lecture11slides - Wednesdays Topics 1 2 3 Project#6...

This preview shows pages 1–8. Sign up to view the full content.

Wednesday’s Topics 1. Project #6 Questions 2. Finish pointers 3. Start on C++ Objects/Classes! Project #6 diagonals b a c k a t a p m w d i n g e t i f k z (1, 3) NE main (3, 4) SE zap j 1 -i 1 0 1 2 3 4 -1 0 1 2 3 -2-1 0 1 2 -3-2-1 0 1 j 1 +i 1 0 1 2 3 4 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7

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

View Full Document
Pointer Review What does this program do? void main(void) { int *ptr; int a[5] = {0}; ptr = &a[1]; *ptr = 3; ptr[1] = 4; *(ptr-1) = 5; ptr += 3; *ptr = 10; // what are all of the values/why? } What does this program do? void main(void) { char s[10] = "Carey"; char *p = s; *p++; cout << s << endl; }
What does this program do? void main(void) { int a[3] = {0}; int *ptr; ptr = a; cout << a << endl; cout << ptr << endl; cout << &ptr << endl; ptr += 3; cout << ptr << endl; cout << ptr - a << endl; } Whats the diff between hmmm and aha? void main(void) { char *hmmm = "hello"; char aha[] = "hello"; cout << (int *)hmmm << endl; cout << (int *)aha << endl; cout << &hmmm << endl; cout << &aha << endl; cout << sizeof(hmmm) << endl; cout << sizeof(aha) << endl; }

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

View Full Document
What does it do? void swap(int *pa, int *pb) { int *t; t = pa; pa = pb; pb = t; } void main(void) { int a = 5, b = 6; swap(&a,&b); cout << a << " " << b <<endl; int c[2] = {10, 11}; swap(c,c+1); cout <<c[0] << " " << c[1] <<endl; } Fix it!
What’s wrong with it? char *GetName(void) { char temp[100]; cout << "Enter your name: "; cin >> temp; return(temp); } void main(void) { char *ptr; ptr = GetName(); cout << ptr; }

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

View Full Document
How is it represented in memory? void main(void) { char *three[3] = {"larry","moe","curly"}; char stooges[3][6] = {"larry", "moe", "curly"}; cout << three[1] << endl; cout << stooges[2] << endl; } What’s wrong with it? void swat(int *p) { *p = 5; } void main(void) { int *a; swat(a); cout << *a; }
Classes: First the C structure A “structure” is a special data type that lets us aggregate many different variables into one big variable: Example: What are the components of the current time? Hours, Minutes, Seconds This is how we define a new structure data type .

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}