While creating a new object in Java, does it give me a memory location, or does it give me a pointer which holds the address of a memory location.
In C, I would do
typedef struct node
{
int data;
struct node* left;
struct node* right;
}Node;
And to get a new Node, I would do
Node* node = malloc(sizeof(Node))
And to access the internal members,
I do node->data, node->left and node->right
To get a new Node, I could also do Node node; and access the members as
node.data. node.left and node.right
In Java, I just do
class Node
{
int data;
Node left;
Node right;
public Node(int data)
{
this.data = data;
left = null;
right = null;
}
}
And to create a new Node, I do
Node node = new Node();
Is node a pointer which holds the address of the actual memory allocated, or it THE actual memory allocated. I'm confused because I just have to do
node.data, node.left and node.right
But don't have an understanding of what actually happens here.