Programming and Graphics

(Kiana) #1

52 Introduction to C++ Programming and Graphics


char q[]= ’zei’;

string n[3]={"who", "am", "I?"};

string b[]={"who", "are", "they?"};

The size ofqis four, as a final 0 is appended to indicate the end of a character
array.


To declare and initialize a 2×2 matrixAwhose elements are real numbers
registered in double precision, we write


double A[2][2] ={{1.0, 2.0},{4.5,-3.5}};

or


double A[][] ={{1.0, 2.0},{4.5,-3.5}};

which sets:A[0][0] = 1.0,A[0][1] = 2.0,A[1][0] = 4.5,A[1][1] =− 3 .5.


Thus, the matrix elements are initialized row-by-row.


Similarly, we can write


char D[2][3]={{60, 61, 65},{62, 63, 66}};

string C[2][3]={{"who", "am", "I?"},{"who", "is", "she?"}};

string C[][]={{"who", "am", "I?"},{"who", "is", "she?"}};

Problems


3.2.1.A vector is declared and initialized as:


double v[128] ={4.0};

What are the components of this vector?

3.2.2.A character vector is declared and initialized as:


char v[128] ={ 67 };
What are the components of this vector?
Free download pdf