+ 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

5th Apr 2018, 12:49 PM
Tanay
Tanay - avatar
5 Respostas
+ 2
Nope, vector<int> adj[] and vector<int>* adj are the same, but just as arguments in function definitions.
5th Apr 2018, 2:03 PM
Timon Paßlick
+ 6
thank you both nonzyro and Timon Paßlick for explanation .
5th Apr 2018, 2:13 PM
Tanay
Tanay - avatar
+ 5
so what you're saying is vector<int> adj[] and vector<int> &adj are same?
5th Apr 2018, 2:02 PM
Tanay
Tanay - avatar
+ 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.
5th Apr 2018, 1:51 PM
Timon Paßlick
+ 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.
5th Apr 2018, 1:37 PM
non