Thread: how would you switch to pointer arithmatic?

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    5

    how would you switch to pointer arithmatic?

    We have to write a program that multiplies matricies, and i showed her the code below and she told me it had to use pointer arthimatic and I have no clue how to make the switch. It is probably a simple procedure but C programming and I make nothing easy...

    thanks if anyone can help.

    Code:
    void matrix_mul( int *mat1, int *mat2, int *mat3 )
    {
      int i,j,k;
      for ( i=0; i<9; i++) mat3[i]=0;
      for ( i=0; i<3; i++ )
      for ( j=0; j<3; j++ )
      for ( k=0; k<3; k++ )
       mat3[i+3*j] += mat1[i+3*k] * mat2[k+3*j];
    }
    Last edited by irishpoison; 03-27-2003 at 10:18 AM.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    5
    i wish I could say that your post helped me Salem but my problem lies in the fact that I dont understand anything with pointer arithmatic and my teacher has been less helpful then i would like...thanks though, ill try to figure it out

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Salem's post is trying to show you that:
    Code:
    mat3[i+3*j] += mat1[i+3*k] * mat2[k+3*j];
    is the same as:
    Code:
    *(mat3 + i + 3 * j) += (*(mat3 + i + 3 * k) ) * (*(mat2 + k + 3 * j));
    Well, I didn't understand your question.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    5
    oh, that makes sense...

    thanks to both of you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  2. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 02:36 AM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. How did you master pointers?
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-17-2006, 08:23 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM