Why do C and C++ compilers allow array lengths in function signatures when they're never enforced?

后端 未结 10 1540
终归单人心
终归单人心 2020-11-22 06:59

This is what I found during my learning period:

#include
using namespace std;
int dis(char a[1])
{
    int length = strlen(a);
    char c = a         


        
10条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 07:57

    To tell the compiler that myArray points to an array of at least 10 ints:

    void bar(int myArray[static 10])
    

    A good compiler should give you a warning if you access myArray [10]. Without the "static" keyword, the 10 would mean nothing at all.

提交回复
热议问题