sizeof on argument

前端 未结 4 1891
感动是毒
感动是毒 2021-01-29 09:40

Even with int foo(char str[]); which will take in an array initialized to a string literal sizeof doesn\'t work. I was asked to do something like strlen and the app

4条回答
  •  误落风尘
    2021-01-29 09:50

    You cannot pass an array as a function parameter, so you can't use the sizeof trick within the function. Array expressions are implicitly converted to pointer values in most contexts, including function calls. In the context of a function parameter declaration, T a[] and T a[N] are synonymous with T *.

    You'll need to pass the array size as a separate parameter.

提交回复
热议问题