Dynamic Arrays - For(int I=0; I<height;I++) Image[I] =...

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

View Full Document Right Arrow Icon
Dynamic Arrays Int a[20]; Int *p = &a[5]; Cout<<p-a<<endl; //prints 5 Int m[5][6] = {………}; For(int I=0; I<5;I++){ For(int j=0;j<6;j++) Cout<<*(*(m+I)+j) <<” “; //same as m[I][j] Cout<<endl; } Dynamic Arrays Int *parr = new int[10 ];//any integer expression>=0, can be a variable Int n; Cin>>n; Int *a = new int[n]; For(int I=0; I<n;I++) Cin>>a[I]; //when done, delete it delete [] a; a=NULL; Dynamic 2D arrays Unsigned char **image; Int height, width; Cin>>height>>width; Image = new unsigned char *[height];
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: For(int I=0; I<height;I++) Image[I] = new unsigned char[width]; For(int I=0;I<height;I++) For(int j=0;j<width;j++) Cin>>image[I][j]; Void printImage(unsigned char **im, const int height, const int width) { for(int y=0;y<height;y++){ for(int x=0;x<width;x++) cout<<in[y][x]<<” “; cout<<endl; } } //delete 2D array for(int I=0;I<height;I++) dlete image[I]; delete image; image = NULL; char **b; b=new char *[100]; for(int q=0;q<100;q++) b[q]=new char[q+1];...
View Full Document

This note was uploaded on 04/17/2008 for the course ECE APS105 taught by Professor Maclean during the Spring '08 term at University of Toronto- Toronto.

Page1 / 2

Dynamic Arrays - For(int I=0; I<height;I++) Image[I] =...

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

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