w4 - CSC209 C pointers and strings Kante Easley University...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSC209: C pointers and strings Kante Easley University of Toronto June 3, 2009 Kante Easley CSC209 CSC209: Arrays In C arrays are contiguous chunks of memory Arrays contain lists of items of a given type 10 ints ⇒ 40 bytes Each in is 4 bytes. No extra information is stored. There is no runtime checking The size of the array is not stored. Kante Easley CSC209 CSC209: Initializing Arrays Declaring/defining arrays: int a[10]; /*declare ’a’ as an array of 10 ints*/ sizeof(a) == 10 * sizeof(int) == 40; Static initialization: char letters[4] = {’a’, ’b’, ’c’, ’d’}; Initialization loop: for(i = 0; i < N; i++) {! a[i] = 0;! } Kante Easley CSC209 CSC209: Arrays It is your responsibility to keep track of: 1 The size of the array. 2 Whether index variables are the correct size 3 ??? Sometimes a maximal size is defined in C programs You can use preprocessor directives for this #define #ifdef ... #else ... #endif #ifndef ... #endif Kante Easley CSC209 CSC209: Pointers Pointers are a higher level version of a memory address. Pointers contain type information char *cptr; declares a pointer to a char allocates space to store a pointer (to a char) char c = ’a’; cptr = &c; &c gets the address where c is stored the value in cptr is the memory address where the value in c is stored *cptr = ’b’; b will be stored at the memory address stored in cptr....
View Full Document

{[ snackBarMessage ]}

Page1 / 22

w4 - CSC209 C pointers and strings Kante Easley University...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online