The Gateway to Computer Science Excellence
+1 vote

Why here implementation A is wrong.I feel it is correct.

in Programming by Active (1.8k points) | 56 views
head is a pointer of type node, which contains the address of the first node. head will be passed as parameter to this function insert, so to hold a pointer we need a double pointer variable.

for example

int i;

int *a = &i;

int **b =&a;

so, technically code 2 is correct but not code 1.
Thank you


Linked list nodes are like {Data , Next node ptr}

Address of head = 4000.

Address of head_ref = 5000

Head_ref {4000}|

Head{1000} -> {1,2000} -> {2,3000} -> {3, NULL}


NewNode{x, NULL}  (suppose address of NewNode 6000)

After implementation first code

NewNode{x, 1000}


I here looking everything is fine , how implementation is wrong. Please describe .I am not getting
@manu sir,

head_ref is pointer to head pointer thats why ** is correct

and also head is pointer to LL so simply * is also correct. I think everything looks fine.!
Manu sir,

 As you said, to hold a pointer variable we a need double pointer variable.. then what type of variable do we need to hold the address of a pointer type variable?
I feel code 1 is also correct.
I am sorry! I think code 1 is also correct, as it's pass by value.

If function insert is called as insert(1000,5); then head will contain the value 1000, we are not storing the address of head.

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,322 answers
105,159 users