pointers - Purpose of *,& symbol behide datatype? -


i learning implement graph using c++. came across see follow code. explain function of symbols * , & behide data type "vertex" , "string"?

#include <iostream> #include <vector> #include <map> #include <string>  using namespace std;  struct vertex {   typedef pair<int, vertex*> ve;   vector <ve> adj; //cost of edge, distination vertex   string name;   vertex (string s) : name(s) {} };  class gragh { public:   typedef map<string, vertex *> vmap;   vmap work;   void addvertex (const string&);   void addedge (const string& from, const string&, double cost); };  void gragh::addvertex (const string &name) {   vmap::iterator itr = work.find(name);   if (itr == work.end())   {     vertex *v;     v = new vertex(name);     work[name] = v;     return;   }   cout << "vertex alreay exist";  }  int main() {   return 0; } 

'*' means de-reference i.e. go address of variable address lies in pointer.

int x=*p;

this means x have value of memory address whom p pointing.

x=&p;

this means x have address of memory location p resides.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -