Why use an asterisk “[*]” instead of an integer for a VLA array parameter of a function?

后端 未结 2 1572
不思量自难忘°
不思量自难忘° 2020-11-28 08:48

When using variable-Length Array as parameter in function

int sum(int n, int a[n]);

it is easy to understand first para

2条回答
  •  抹茶落季
    2020-11-28 09:15

    When you put the star in an actual function it gives this error test.c:3: error: ‘[*]’ not allowed in other than function prototype scope. After some research this is actually a way to declare a VLA in a function prototype, with the * in place of the variable name. VLA.
    The issue at hand here is that if you put a variable instead of the star for a VLA, it will tell you that it is undeclared, so the star is a way that c99 built in to get around that.

提交回复
热议问题