Week 6 notes

Week 6 notes - Pointer and Array Equivalences...

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

View Full Document Right Arrow Icon
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));
Background image of page 1

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

View Full DocumentRight Arrow Icon
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;
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.

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 Right Arrow Icon
Ask a homework question - tutors are online