-2
int t, i;
cin >> i;

int*s = new int[i];

for (t = 0; t < i; t++) {
    s[t] = t;//How??
    cout << s[t] << "_" << &s[t] << endl;
}

int*f = new int;
*f = t; // Whhhhhy???
delete f;
delete[] s

I declared an array type and an integer as dynamic memory.

While I can assign any ordinary integer value to *f (and pointer value for f), it keeps warning me when assigning an integer value to *s[t].

I have no idea as to why.

Bob Gilmore
  • 12,608
  • 13
  • 46
  • 53
DD_IaZ
  • 3
  • 3
  • 5
    Welcome to Stack Overflow! Sounds like you could use a [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – NathanOliver Jan 18 '17 at 16:20
  • And.. What you are confused about? – Algirdas Preidžius Jan 18 '17 at 16:21
  • 1
    The *reason* we say you could use one, is because this is a set of problems that really are best answered with a book, since the authors have the time and space to give you an explanation of things like initialization, object lifetime, and management of memory and other resources. – jaggedSpire Jan 18 '17 at 16:21
  • 1
    Also missing: `delete[] s`. – MSalters Jan 18 '17 at 16:22

2 Answers2

2

The reason that you get a warning is because s[t] is shorthand for *(s+t), so *s[t] is shorthand for **(s+t). That's one too many *.

MSalters
  • 173,980
  • 10
  • 155
  • 350
0

The [] operator includes an implicit '*'. Assign your value to s[t] rather than *s[t]

Dale Wilson
  • 9,166
  • 3
  • 34
  • 52