CMPT 125 Lecture 2: L2 P2

30 views5 pages

Document Summary

The variable array is really a pointer to int. The elements are stored in the memory in a contiguous block, starting from the position array. Arithmetics of pointers: note that size of int = 4. *(array+3) = 25; printf("array[3] = %d\n", array[3]); // array[3] = 25; Array bounds int array[10] = {0, 1, 8, 2, 18, 3, 6, 2, 2, -4}; *common bug for (int i=0; i < length; i++) ; { Do something array[i]; for (int i=0; i < length , i++) { It is possible to have several commands in the increment part, separated by commas. for (int i=0; i < length; i++) a single instruction array[i]; If the body of the loop contains only one instructions, the curly braces can be omitted. (don"t do it!) Exercises: write a function that gets two arrays of ints of length n, and compares them. If the contents of the arrays are identical, it returns -1.

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