cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
user name:
password:
Forgot your password?
please wait
try again
cancel
forgot your password?
sign up
log in
[Legacy version]
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
HELP PLS
HELP PLS
Aug 31, 2016 at 8:08pm
Aug 31, 2016 at 8:08pm UTC
mvgnum
(11)
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?
Aug 31, 2016 at 8:12pm
Aug 31, 2016 at 8:12pm UTC
cire
(8284)
1
2
c =
new
int
; *c = ***a;
Although, that isn't what your diagram asks for. That would be:
c = **a;
Last edited on
Aug 31, 2016 at 8:18pm
Aug 31, 2016 at 8:18pm UTC
Aug 31, 2016 at 8:16pm
Aug 31, 2016 at 8:16pm UTC
mvgnum
(11)
YOU ARE A GENIUS BRO!
Aug 31, 2016 at 8:18pm
Aug 31, 2016 at 8:18pm UTC
cire
(8284)
You should read the edit.
Aug 31, 2016 at 8:34pm
Aug 31, 2016 at 8:34pm UTC
mvgnum
(11)
compiling error :/
Topic archived. No new replies allowed.