{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

12DynamicArraysLarge

# 12DynamicArraysLarge - items you want in the array s Second...

This preview shows pages 1–3. Sign up to view the full content.

1 CMSC 106 Lecture Set #12 – Dynamically Allocated Arrays Set Started: Wednesday, November 30, 2011 Pointers and Arrays square6 Name of an Array = Address of 0 th element square6 Can use pointers to indicate other elements of the array square6 Can use pointer arithmetic to traverse an array square6 When an array is passed as the argument to a function – only the address indicated is passed

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Statically allocated array square6 char name[] = “Jandelyn”; square6 int sizes[5] = {4,6,2,4,8}; square6 double scores[10]; square6 Name of array is a constant pointer scores++; name+=2; *(name+2) = ‘z’; Filling statically allocated array square6 Size of array must be known at COMPILE time square6 Always stays the same size (can use only a portion of the allocated space if you wish) square6 Must make sure you stay “in bounds”
3 Dynamically allocating space square6 calloc square6 First argument must indicate the number of
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: items you want in the array s Second argument must indicate the size of one of those array items s Allocates a single sequential and contiguous block of memory of the size needed s Returns NULL if the request cant be fulfilled s Returns the Address of that space if it can be Rules s Space is allocated from a place called the heap s Once allocated, the size is fixed (cant change size and remain at that location in memory) s The space is sequential and contiguous so can still use array index or pointer method (exactly the same as a statically allocated array) s The name of the Array is NOT CONSTANT but be careful not to lose the location of the beginning of the array s Once allocated and you are done using it, the space must be freed...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

12DynamicArraysLarge - items you want in the array s Second...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online