Why it is not allowed to pass arrays by value to a function in C and C++?

前端 未结 6 797
心在旅途
心在旅途 2020-12-30 10:24

C and C++ allows passing of structure and objects by value to function, although prevents passing arrays by values.

Why?

6条回答
  •  囚心锁ツ
    2020-12-30 10:53

    In C/C++, internally, an array is passed as a pointer to some location, and basically, it is passed by value. The thing is, that copied value represents a memory address to the same location.

    In C++, a vector is copied and passed to another function, by the way.

提交回复
热议问题