I don't understand pointers & arrays. Keep getting error in compiling

This is a discussion on I don't understand pointers & arrays. Keep getting error in compiling within the C Programming forums, part of the General Programming Boards category; Here is my code: Code: #include <stdio.h> #include <stdlib.h> #include <math.h> #define DIMENSION 3 #define SIGN(i, j) pow(-1, i+j) double ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    16

    I don't understand pointers & arrays. Keep getting error in compiling

    Here is my code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    
    #define DIMENSION 3
    #define SIGN(i, j) pow(-1, i+j)
    
    
    double det(double entries)
    {
      int dim = DIMENSION;
      int k, l, m;
      double submatrix[dim-1][dim-1];
      double det;
    
    
      det = 1;
     
      if(dim == 2)
      {
        det = ( (entries[0][0]) * (entries[1][1]) ) - ( (entries[0][1]) * (entries[1][0]) );
        return det;
    What I don't understand, is that I keep getting the error message "subscripted value is neither array nor pointer" for the line:
    Code:
    det = ( (entries[0][0]) * (entries[1][1]) ) - ( (entries[0][1]) * (entries[1][0]) );
    Can someone explain what I've done wrong? What is the 'subscripted value'

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,676
    Code:
    double det(double entries)
    Notice how there are no [ brackets ] after entries? That means there is just one double, not an array of doubles, or a 2-d array of doubles. So when you do entries[0][0], you're trying to treat a double like a 2-d array of doubles, which is a no-no. See if this helps: 7.2 Passing Arrays to Functions.

    EDIT: This link may be better: http://c-faq.com/~scs/cclass/int/sx9a.html.
    Last edited by anduril462; 11-22-2011 at 01:14 PM.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    16
    Ah! thats annoying. So is there no way to pass a multi-dimensional array to a function without saying any of its dimensions?

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    16
    Thanks, got it sorted now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Understand pointers
    By Aphex in forum C Programming
    Replies: 3
    Last Post: 08-12-2010, 10:07 PM
  2. i cant understand something in pointers
    By nik2 in forum C Programming
    Replies: 2
    Last Post: 02-12-2010, 01:26 PM
  3. Compiling all i understand so far
    By brian75 in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2008, 05:41 AM
  4. Trying To Understand Pointers!
    By pobri19 in forum C Programming
    Replies: 4
    Last Post: 05-08-2008, 02:28 AM
  5. Something I still don't understand about pointers
    By Extol in forum C++ Programming
    Replies: 11
    Last Post: 03-01-2003, 06:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21