Week 6 notes

Week 6 notes - Pointer and Array Equivalences...

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

Pointer and Array Equivalences Assuming int buf[5];           int x; is the same as *(int*)((char*)buf+i*sizeof(int)) if we  want to do pointer arithmetic using char* instead of int* a[0] a:100 a[1] a:104 a[2] a:108 Working with Memory Blocks void* memcpy(void *dest, const void *src,int len); It copies a range of memory from "src" to "dest" a "len"  number of bytes. It should be used only in sections of memory that do  not overlap. Example:   #define MAXARRAY 1000 double a[MAXARRAY]; double b[MAXARRAY]; //Fill up a, copy a to b for(int i=0;i<MAXARRAY;i++){  b[i]=a[i]; } Or you can use memcpy memcpy((void*)b, const  void*)a,MAXARRAY*sizeof(double));

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

View Full Document
int memcmp (void *p, void * q, int len) - It returns 0 if the 2 blocks are equal - or different than 0 if different void *memmove(void *dest, void *src, int len) - moves a block of memory from src to dest - similar to memcpy - blocks can overlap void *memchr(void *p,int val, int len) - It fills block p->p+len with char in "val" double x; double y; x=6.38; y=x;
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/18/2012 for the course CS 240 taught by Professor Rego during the Fall '08 term at Purdue.

Page1 / 9

Week 6 notes - Pointer and Array Equivalences...

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

View Full Document
Ask a homework question - tutors are online