Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:32:52+00:00 2026-05-30T18:32:52+00:00

I have read the topic about pointer, but i still have some question. //

  • 0

I have read the topic about “pointer”, but i still have some question.

// graph.cpp

struct Edge {
    int from;
    int to;
    unsigned int id;
    Edge(): from(0), to(0), id(0) {};
};

struct Vertex {
    int label;
    vector<Edge> edge;
};

class Graph: public vector<Vertex> {
    int gid;
    unsigned int edge_size;
};

if I declare a iterator in another file

bool get_forward_root (Graph &g, Vertex &v, vector<Edge*> &result) {
    for(vector<Edge>::iterator it = v.edge.begin(); it != v.edge.end(); it++) {
        if(v.label <= g[it->to].label)
        result.push_back(&(*it));
    }
}

In my understanding, it can be viewed as pointer, since v.edge.begin() is the first Edge object in vector<Edge>, but what is &(*it) ?

Question 2. What is the difference between g, &g, *g ?

In my understanding:

  • &g is the memory address.
  • *g is a Graph pointer point to a graph object, so we can use Graph *g = new Graph();
  • g is a Graph object

the difference between *g and g is how we use, for example the two conditions are the same:

condition 1:

Graph *g = new Graph();
g->gid = 0;

condition 2:

Graph g;
g.gid = 0;

Question 3.

what is below meaning?

Graph &g

and why we use g[it->to].label not &g[it->to].label
Thank very much:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:32:54+00:00Added an answer on May 30, 2026 at 6:32 pm

    Question 1: what is &(*it)

    it acts like a pointer, but it’s not a pointer. If it were a pointer, &*it would be the same as it. In the general case, &(*it) is the address (a real pointer) of the object that the iterator it points to. We can assume here that the & operator was not overloaded.

    Question 2: What is the difference between g, &g, *g?

    g is g. &g is the address of g. *g is the object g points to (if g is a pointer). Your 2 conditions (I don’t understand why you call them conditions) do pretty much the same thing, yes.

    Question 3: what is Graph &g?

    It’s called a reference. When defined, it should be immediately initialized. Think of a reference as another name of an object. (Better, read a book, see below).

    All of your questions will be thoroughly answered in any decent C++ beginner book. I especially recommend Lippman’s C++ primer for this purpose. Find other good titles here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read questions and answers about this topic but I still have some
I have read all the previous posts about this exact topic, but I still
I have read through some articles on this topic but I am still cautious
I have read some posts about this topic and the answers are comet, reverse
I have read a few bits and bobs online about this topic but found
I've read almost all the other questions about the topic, but my code still
I have read a couple of posts on this topic, but neither addresses my
i have read some topics on this, but i don't quite think it answers
I've read many topic on stackoverflow,and google, about this argument but i can't orient
I've read several of the posts on stack overflow already about this topic, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.