CS137 Lecture Notes - Lecture 14: Array Data Structure, C Dynamic Memory Allocation

51 views3 pages

Document Summary

#include void swap (int *p, int *q) int main () int i=1, j=2; swap (&i, &j); printf( %d, %d\n , i, j); return 0; #include int *largest (int a[], int n) int m=0; for (int i=1; ia[m]) m=1; // or return a+m int main () int test[] = {0,1,2,3,2,1,0}; int *p = largest (test, sizeof(test)/sizeof(test[0])); Operations: add an integer to a pointer, subtract an integer from a pointer, subtract one pointer from another, ex: int a[8], *p, *q, i; Int sum (int a[], int n) int sum = 0; for (int *p = a, p < a+n, p++) return sum; sum += *p; int main () int test[] = {1,2,3}; int s = sum (test, 3); Pointer to nothing int *p = 0: double *q = 0; //void free (void *p); int *numbers (int n)

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