sizeof on argument

前端 未结 4 1823
感动是毒
感动是毒 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 10:15

    You can't use sizeof here. In C arrays are decayed to pointers when passed to functions, so sizeof gives you 4 or 8 - size of pointer depending on platform. Use strlen(3) as suggested, or pass size of the array as explicit second argument.

提交回复
热议问题