COM SCI 31 Lecture 13: Pointers and Arrays

38 views3 pages
28 Nov 2017
School

Document Summary

Lecture 11/13 const int max_size = 5; double da[max_size]; int k; double* dp; for(k = 0; k < max_size; k++) da[k] = 3. 6; for(dp = &da[0]; dp < &da[max_size]; dp++) *dp = 3. 6; for(dp = da; dp < da + max_size; dp++) dp* = 3. 6; Or const string* a int lookup(const string a[], int n, string value) a[k] -> const string a[] not declaring an array. rat, rat, zebra, pig, rat int m = lookup(b, 10, zebra); //7 int m = lookup(&b[0], 10, zebra); //7. //the above two mean the same thing int k = lookup(b, 5, zebra); //-1 int h = lookup(&b[4], 5, zebra); //these two mean the same thing int h = lookup(b + 4, 5, zebra); //you start at b[4] //int h = 3, but zebra is located at position 7 in the array int h = 4 + lookup(b + 4, 5, zebra); //converts 3 to b"s system a[k]

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Questions