Array syntax in C

What's the difference between

int * a[10];

and

int (*b)[10];

I know that the first one is an array of pointers to integers, but what about the second? If I try to assign

int (*c)[10] = a;

What am I actually doing with c?

+5
source share
5 answers

See if you can install a command cdeclfor your system. (On Ubuntu ,.sudo apt-get install cdecl ) There is also a cdecl.org web interface .

Here is what he told me for your examples on my system:

$ cdecl
Type `help' or `?' for help
cdecl> explain int * a[10];
declare a as array 10 of pointer to int
cdecl> explain int (*b)[10];
declare b as pointer to array 10 of int
cdecl> 
+10
source

The second is a pointer to an array of 10 integers. Where? God knows; you never initialized it.

a, 10 , a ... .

+5

- ( , ) , : http://www.antlr.org/wiki/display/CS652/How+To+Read+C+Declarations

( , . , ; - . , ; - . , . ; - . ; , . , .

, C.

, , : cdecl, , -: http://cdecl.org/

+5
  • int * a [10] - , , 10 (),

    a[0] = (int *)calloc(10, sizeof(int));
    a[1] = (int *)calloc(50, sizeof(int));
    

    .. a (10 * 4) = > 40.

  • int (* b) [10] - , , .. b 10,

    b = &(integer array[10]);
    

    :

    int c[10];
    int (*b)[10];
    b = &c;
    

    , .

+2
  • 10 .
  • - , .
  • , a, 10 , 10 , .

:

int d[10];
int (*c)[10] = d;

:

C /

+1

All Articles