Why does C and C + + compilers allow array lengths in function signatures when they ' re never enforced?
This is because, a long time ago (in fact, not long), the programming process found that this situation
#include<iostream>using namespaceSTD;intDis(Chara[1]){ intlength=strlen(a); CharC=a[2]; returnlength;}intMain(){ Charb[4] = "ABC"; intC=Dis(b);cout<<C; return 0;}
function dis parameter a[1] After the number 1, does not work, in fact, write 2.3.4 can, this is also a lot of people know, in the spirit of inquiry to think a bit, since it does not work, then why not prohibit this behavior, still is to the StackOverflow (really is God station) Ask questions and get answers from many great gods.
Why does C and C + + compilers allow array lengths in function signatures when they ' re never enforced?
This is a better answer.
It's a quirk of the syntax for passing arrays to functions.
Actually it isn't possible to pass an array in C. If You write syntax this looks like it should pass the array and what actually happens are that a pointer to the first element Of the array is passed instead.
since The pointer does not include any length information, the contents of Your ["
in the function formal parameter list is actually ignored.
The decision to allow this syntax is made in the 1970s and have caused much confusion ever since ...
Other wonderful answers, specific can see here, will not move over.
Http://stackoverflow.com/questions/22677415/why-do-c-and-c-compilers-allow-array-lengths-in-function-signatures-when-they
The length of the array in the parameter list of the C + + function is thought