+ 6
About Vector in c++.
Here in this code when function add_Edge is called in parameter adj is passed but when in function definition there is array of vector i guess. I don't Understand what is going on with this vector ( Adj ) because even though the reference is not declared in receiving parameter it is modifying actual vector. please make me understand what is going on here in this Code. Any one who can explain this? https://code.sololearn.com/cwY2Mc5If5g3
5 ответов
+ 2
Nope,
vector<int> adj[]
and
vector<int>* adj
are the same, but just as arguments in function definitions.
+ 6
thank you both nonzyro and Timon Paßlick for explanation .
+ 5
so what you're saying is
vector<int> adj[]
and
vector<int> &adj are same?
+ 2
A type arr[optional] argument is literally a pointer.
To copy arrays into functions, use std::array.
There are also C functions for this, of course.
+ 1
I just glanced at your code and noticed you're passing by reference (using [] in your function prototype). A regular int[] will do the same.
To clarify: The address of the memory location is passed. So alterations are persistent.