HELP PLS
HELLO, CAN U HELP?
DIAGRAM:
http://i65.tinypic.com/nbcjmw.png
Use the above diagram for Question I. The shaded boxes represent pointers.
I) a) Declare and allocate memory to implement the diagram. That is, write C++ statements that will create what is shown in the diagram
b) Where are each of the items in memory?
c) Deallocate all memory
HERE IS THE CODE:
#include <iostream>
#include <string>
using namespace std;
int main()
{
//Variables definition
int ***a;
int **b;
int *c;
//Levels of indirection for a
a = new int **;
*a = new int *;
**a = new int;
*** a = 18;
//Levels of indirection for b
b = new int *;
*b = new int;
** b = 22;
*c = new int;
*c = *a;
//Display
cout << "Addresses of 18 are: " << a << " " << *a << " " << **a << " " /*<< *c <<*/ << endl;
cout << "Addresses of 22 are: " << b << " " << *b << " " << endl;
//Delete used pointers
delete **a;
delete *a;
delete a;
a = nullptr;
delete *b;
delete b;
b = nullptr;
return 0;
}
I HAVE AN ISSUE WITH :
*c = new int;
*c = *a;
ANY CLUE?
1 2
|
c = new int;
*c = ***a;
|
Although, that isn't what your diagram asks for. That would be:
c = **a;
Last edited on
YOU ARE A GENIUS BRO!
You should read the edit.
compiling error :/
Topic archived. No new replies allowed.