3
# include <stdio.h>
# include <stdlib.h>    
int main(int argc, char *argv[])
{
    int daytab[2][13];
    int (*daytab)[13];
    int *px;

    return EXIT_SUCCESS;
}

I am studying pointers and having difficulty reading the int (*daytab)[13] declaration. int *px is read as px is a pointer to a int.

How do you read int (*daytab)[13]?

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
user2688772
  • 245
  • 1
  • 3
  • 7

1 Answers1

8

Apply spiral rule: is a technique known as the Clockwise/Spiral Rule which enables any C programmer to parse in their head any C declaration!

There are three simple steps to follow:

  1. Starting with the unknown element, move in a spiral/clockwise direction; when encountering the following elements replace them with the corresponding English statements:

    [X] or []
    => Array X size of... or Array undefined size of...

    (type1, type2)
    => function passing type1 and type2 returning...
    *
    => pointer(s) to

  2. Keep doing this in a spiral/clockwise direction until all tokens have been covered.
  3. Always resolve anything in parenthesis first! It will make sense;

     +---------+              
     | +-----+ |     
     | ^     | |      ( daytab)        // daytab
int (*daytab)  [13];  (*daytab)        // daytab is a pointer
 ^   ^       | |      (*daytab)[13]    // daytab is a pointer to an array of 13
 |   |       | |      int(*daytab)[13] // daytab is a pointer to an array of 13 ints 
 |   +-------+ |            
 +-------------+    

Here are some answers to this question. Read them all.

Community
  • 1
  • 1
haccks
  • 104,019
  • 25
  • 176
  • 264