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

  • SEARCH
  • Home
  • 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 852137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:32:44+00:00 2026-05-15T07:32:44+00:00

alright, im looking at a code here and the idea is difficult to understand.

  • 0

alright, im looking at a code here and the idea is difficult to understand.

#include <iostream>
using namespace std;
class Point
{
public :
    int X,Y;
    Point() : X(0), Y(0) {}
};

void MoveUp (Point * p)
{
    p -> Y += 5;
}

int main()
{
    Point point;
    MoveUp(&point);
    cout << point.X << point.Y;
    return 0;
}

Alright, so i believe that a class is created and X and Y are declared and they are put inside a constructor

a method is created and the argument is Point * p, which means that we are going to stick the constructor’s pointer inside the function;

now we create an object called point then call our method and put the pointers address inside it?

isnt the pointers address just a memory number like 0x255255?

and why wasnt p ever declared?

(int * p = Y)

what is a memory addres exactly? that it can be used as an argument?

  • 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-15T07:32:45+00:00Added an answer on May 15, 2026 at 7:32 am

    p was declared.

    void MoveUp (Point * p)
    {
        p -> Y += 5;
    }
    

    is a function that will take a pointer to a Point and add 5 to its Y value. It’s no different to the following:

    void f(int n) {
        printf ("%d\n", n);
    }
    :
    int x = 7;
    f(x);
    

    You wouldn’t say n wasn’t defined in that case. It’s the same for p in your case.

    Perhaps some comments in the code would help:

    #include <iostream>
    using namespace std;
    class Point
    {
    
    public :
        int X,Y;
        Point() : X(0), Y(0) {}       // Constructor sets X and Y to 0.
    };
    
    void MoveUp (Point * p)           // Take a Point pointer p.
    {
        p -> Y += 5;                  // Add 5 to its Y value.
    }
    int main()
    {
        Point point;                  // Define a Point.
        MoveUp(&point);               // Call MoveUp with its address.
        cout <<point.X << point.Y;    // Print out its values (0,5).
        return 0;
    }
    

    Pointers are simply a level of indirection. In the code:

    1   int X;
    2   int *pX = &X;
    3   X = 7;
    4   *pX = 7;
    

    the effect of lines 3 and 4 are identical. That’s because pX is a pointer to X so that *pX, the contents of pX, is actually X.

    In your case, p->Y is the same as (*p).Y, or the Y member of the class pointed to by p.

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

Sidebar

Related Questions

Alright...I am here looking for some bread crumbs. This is my code: using System;
Alright, this is my current code snippet: namespace bai = boost::asio::ip; bai::tcp::socket tcp_connect(std::string hostname,
Alright, so I've been looking at functions and using them as arguments. Let's say
Alright so I have been looking around (on SO and Google) to see if
Alright, What Im looking for is a script that would automatically add a date
Alright I don't see why this isnt working. It seems pretty simple. Here is
Alright so I have no idea how to even begin doing this But basically
Alright, so I got this code for gluLookAt: lookAt = new Vector3f(-player.pos.x, -player.pos.y, -player.pos.z);
I'm looking to build a menu using a ListView (I'm open to using anything
Alright, I'm at my wits end with this one. I am using an open-source

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.