The question "what is the difference between int* and int[]?" is a less trivial question than most people will think of: it depends on where it is used.
In a declaration, like extern int a[];
it means that somewhere there is an array called a
, for which the size is unknown here. In a definition with aggregate initialization, like int a[] = { 1, 2, 3 };
it means an array of a size I, as programmer, don't want to calculate and you, compiler, have to interpret from the initialization. In a definition without initialization, it is an error, as you cannot define an array of an unknown size. In a function declaration (and/or) definition, it is exactly equivalent to int*
, the language specifies that when processing the types of the arguments for functions, arrays are converted into pointers to the contained type.
In your particular case, as declaration of members of a class, int a[];
is an error, as you are declaring a member of an incomplete type. If you add a size there, as in int a[10]
then it becomes the declaration of an array of type int
and size 10, and that will reserve space for 10 int
inside each object of the class. While on the other hand, int *b
will only reserve space for a pointer to integers in the class.