Computer Science 2211A/B Lecture Notes - Lecture 12: Array Data Structure

75 views2 pages

Document Summary

Pointers can point to array elements eg. int a[10], *p; p = &a[0]; *p = 5; // store 5 into a[0] If p points to an element of an array, the other elements can be accessed by performing pointer arithmetic. Adding an integer, subtracting an integer, and subtracting one pointer from another. If p points to the array element a[i], then p + j points to a[i+j] If p points to the array element a[i], then p - j points to a[i-j] When on pointer is subtracted from another, the result is the distance between the pointers. If p points to a[i] and q points to a[j], then p - q is equal to i - j. Performing arithmetic on a pointer that does not point to an array element. Subtracting pointers unless both point to elements of the same array. Pointers can be compared using the relational and equality operators.

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 Documents