cs lecture nov 2

cs lecture nov 2 - cs lecture nov 2 Dynamic Storage (ch. 17)

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

View Full Document Right Arrow Icon
cs lecture nov 2 Dynamic Storage (ch. 17) #include<stdlib.h> void *malloc(size_t size); allocates a block of memory of the specified size. an integer defined in stdlib.h (might be int) returns a pointer to something (just a block of memory void free(void *p); release memory allocated by malloc!!! eg. write a function that creates and returns an int array containing 1 to n. #include <stdlib.h> int *numbers(int n) { int big=0; big=*b; for(;b;b++){ if(*b>big) big=*b; } int i,*p; p=(int*)malloc(n*sizeof(int)); for(i=0;i<n;i++) p[i]=i+1; return p; } int main(void) { int *q=numbers(100); printf(“%d\n”,q[50]); 51 free(q); return 0; } Characters char c; normally one byte, however treated as an 8-bit integer
Background image of page 1

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

View Full DocumentRight Arrow Icon
ASCII : 7-bit character code designed for AMERICAN , also there was EBCDIC (rival of ASCII) -invented in 1963 (when memory was very expensive) binary 0000000 ->111111 decimal 0 to 127 0=31 -unprintable control characters (\n,^c) Values 38-57 – numbers 0-9 values 65-90 : capital letters of English
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/10/2011 for the course CS 137 taught by Professor Clarke during the Fall '10 term at Waterloo.

Page1 / 5

cs lecture nov 2 - cs lecture nov 2 Dynamic Storage (ch. 17)

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

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