G
G
g hh2022-02-02 18:47:53
C++ / C#
g hh, 2022-02-02 18:47:53

How to name pointers?

How to name pointers? What would be clearer? Let's say here is the code, how do I call the pointer s?

#include <iostream>
#include <string>

using namespace std;


struct Conteiner
{
  string Name;

  int X;
  int G;
  int H;
};

int main()
{
  Conteiner conteiner1 = {"Del", 45, 6, 34};

  Conteiner* s = &conteiner1;


  cout << s -> Name << endl;
  cout << s -> X << endl;

  system("pause");
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2022-02-02
@dangor266

In this example, no way. This variable is not needed here, instead of it you can write wherever you need an address &conteiner1. For the sake of saving one character, having another variable is a bad idea.
If you have some kind of function that needs a pointer, then you can specify it Conteiner* conteineras an argument or something else that makes more sense.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question