Are vectors passed to functions by value or by reference in C++

前端 未结 4 1416
时光取名叫无心
时光取名叫无心 2020-12-04 06:15

I\'m coding in C++. If I have some function void foo(vector test) and I call it in my program, will the vector be passed by value or reference? I\'m

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 06:58

    when we pass vector by value in a function as an argument,it simply creates the copy of vector and no any effect happens on the vector which is defined in main function when we call that particular function. while when we pass vector by reference whatever is written in that particular function, every action will going to perform on the vector which is defined in main or other function when we call that particular function.

提交回复
热议问题