I have written a question on line 28 and 29 ?
What is the difference in *arr and arr ?
And why we are using (*arr).next and not arr.next ?
I have written a question on line 28 and 29 ?
What is the difference in *arr and arr ?
And why we are using (*arr).next and not arr.next ?
hello @yashsharma4304
arr is a pointer ( a datatype that stores address) .it has no other specialities.
we use dot operator over objects to call its member function or member variable right ?
so first we need to get the object from that pointer(arr).
and for that we are doing (*arr)
(*arr) : is representing an object and we can use dot operator on this object to get the content of its member variable.
So arr is an object of node class. Node class has two data members
Now to access these data members of this class we will write :
(*arr).next or (*arr).data
Right?
Now, if we are writing *arr. Is that * used as a dereference operator or is it something else?
yeah it is dereference operator only.
Ok so if it is a dereferencing operator then it is giving us the value inside arr which is the address of a node to which it is pointing.
And here we are writing :
head = arr;
that means head will now point to arr and will store the address of arr.
But if I write :
head = *arr;
that means head is still pointing to the same node to which it was pointing ?
Indirectly we have not updated the value of head?
Because initially head was pointing to a node and our next node is now arr which stores the address of this previous node. So if I am writing :
head = *arr;
that means I am again copying the same address into head ?
Now, Is this concept right ?
…
see arr is holding some address(say abcd)
then what dereference will do is it will give value present at address abcd.
and becuase at abcd we have stored object , it will give object.
Then what is the name of that object ?
no name bro, becuase we are using new operator.
what new operator does is , it return address of the newly created object .
we have only its address. and with the help of address we can access its member function and variable
Ok now it’s clear. Thank you
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.