I am starting learning C programming.
a[20]
and a[]
I understand a[20]
is a fixed-size array but how about a[]
?
I am starting learning C programming.
a[20]
and a[]
I understand a[20]
is a fixed-size array but how about a[]
?
Copyright © 2021 Jogjafile Inc.
Without knowing the proper context / usage, it's impossible to provide a direct answer, however, let me give example of some commonly used cases:
In a block scope, an array defined with the syntax like
a[]
,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).
In other hand, in the case of a function argument, a syntax like
a[]
,is the same as
and it's not an array, it's a pointer.
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: