Is that fixed-size array? a[]

100 Views Asked by At

I am starting learning C programming.

a[20] and a[]

I understand a[20] is a fixed-size array but how about a[]?

1

There are 1 best solutions below

2
On

Without knowing the proper context / usage, it's impossible to provide a direct answer, however, let me give example of some commonly used cases:

  1. In a block scope, an array defined with the syntax like a[],

    char a[] = "Some Name";
    

    is still a fixed-sized array. The size is obtained from the initializer, for example: the above array has a size of 10 (including the null terminator).

  2. In other hand, in the case of a function argument, a syntax like a[],

    void func (int a[])
    

    is the same as

    void func (int *a)
    

    and it's not an array, it's a pointer.

  3. If this syntax appears as the last element of a structure with more than one named member, this is called a flexible array member. It is an incomplete array type. For example:

    struct s { int n; double d[]; };