lecture11slides

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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; }
Background image of page 2
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; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
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!
Background image of page 4
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; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
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; }
Background image of page 6
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
Background image of page 7

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

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

Page1 / 21

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

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

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