CMPSC 16 Lecture Notes - Lecture 7: Memory Address, Segmentation Fault

21 views3 pages
School
Course
Professor

Document Summary

Lecture 07: c++ arrays, pointers, and pointer arithmetic. For a list of elements, each element is adjacent to the one before in memory. When an array is created, the only memory that is created on the stack is for the elements in the array; no memory is used for the length of the array. Declare an array of 5 doubles: double scores[#]; Declare and initialize: double score[] = {value1, value2, }; Returns the size of the array or the bytes(in bytes) Shows how much memory is put aside on the stack for the array or type. Since the memory address of an array is known, the elements can be accessed randomly without going through the entire array. Each next element is 8 bytes away (for an array of doubles) The number of bytes away is determined by the type of the array values. Int length = sizeof(arrayname) / sizeof(arraytype); for(int a = 0; a < length; a ++){

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

Related Questions