I got this assignment the other day in which I had to convert this project I had done from subscript notation to pointer notation. I dont really understand the syntax used for pointer notation. My program below (using subscript notation) works fine but I dont really know exactly how to go about converting it to pointer notation. Any information would help.
The program just creates two matrices using 2 dimensional dynamic arrays. It then goes on to perform addition, subtraction, and multiplication between the matrices.
int main()
{
int r1=0,c1=0,r2=0,c2=0,b;
cout<<"Which set type do you want: 1. Integer, 2. Float, or 3. Character."<<endl;
cin>>b;
cout<<"First enter the number of rows in first matrix and then the columns."<<endl;
cin>>r1>>c1;
cout<<"First enter the number of rows in second matrix and then the columns."<<endl;
cin>>r2>>c2;
arr[x] = *(arr+x). An array is really just a block of memory in which data of the same kind is stored sequentially.
for example,
1 2 3
struct Example {
int a; int b; int c;
};
If we create a new Example array
Example* test = new Example[3];
Then test will be a pointer to the first element in the array. Lets assume that sizeof(int) == 4 and arr == 0x1000
*arr (or *(arr+0)) will get us the first array element at location 1000. *(arr+1) will get us the second element at location 100C (because our struct has a size of 12 bytes total, arr+1 == (Example*)((char*)arr+12)) which is equivalent to what arr[1] gets us.