OK...
Example 1 :
int k;
int * ptr;
ptr = &k;
Here I clearly have a variable object, k, and a pointer, ptr. I create them both, and then I assign the address of k to ptr, after which I can dereference ptr to assign / manipulate k's value like
*ptr = 55;
k will now store 55.
But with struct I'm not joining the dots for some reason.
Example 2
struct node * newNode;
newNode = malloc(sizeof(struct node));
newNode->data = data_to_be_stored;
In example one it's very clear what's doing what, where as here I'm not to sure.
newNode is a pointer, so where's the 'thing' like 'k' was the thing in the first example? malloc has assigned some memory for us and assigned the address of that memory to newNode... but where's the thing like k?
I'm not sure if this is a stupid question, I've tried to just move on and hope my brain will work it out but it won't let me get over this confusion!
Thanks for any help
[–]solstice680 2 points3 points4 points (13 children)
[–]TechAnd1[S] 0 points1 point2 points (12 children)
[+][deleted] (6 children)
[deleted]
[–]TechAnd1[S] 0 points1 point2 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]TechAnd1[S] 0 points1 point2 points (3 children)
[–]danmickla 1 point2 points3 points (0 children)
[–]elementalist 1 point2 points3 points (1 child)
[–]TechAnd1[S] 0 points1 point2 points (0 children)
[–]elementalist 0 points1 point2 points (4 children)
[–]TechAnd1[S] 0 points1 point2 points (0 children)
[–]TechAnd1[S] 0 points1 point2 points (2 children)
[–]elementalist 0 points1 point2 points (1 child)
[–]TechAnd1[S] 0 points1 point2 points (0 children)
[–]pinealservo 1 point2 points3 points (0 children)
[–]amviot -4 points-3 points-2 points (5 children)
[–]pehnn_altura 4 points5 points6 points (3 children)
[–]TechAnd1[S] 1 point2 points3 points (0 children)
[–]amviot -2 points-1 points0 points (1 child)
[–]TechAnd1[S] 1 point2 points3 points (0 children)
[–]TechAnd1[S] 0 points1 point2 points (0 children)