Here you are passing record pointer by value.

as you call insert(record, 5),stack frame of insert contains a copy
of  record.after this value is modified by calling program,it should
be either returned explicitly to caller program or needs to be passed
by reference,so that calling program refers to it always by address.


On Jan 27, 4:17 pm, nishaanth <[email protected]> wrote:
> Hi guys,
>
> I have a small doubt regarding pointers and functions.
>
> Consider the following prototype
>
> void insert(bst * head, int data);
>
> This function creates a node and inserts the data in the node. Lets say i
> call this function iteratively from main.
>
> main(){
>
> bst* record=NULL;
> insert(record, 5);
> insert(record, 8);
>
> }
>
> I see that record is not getting modified. Now is this related to call by
> value. But since we are passing pointers shouldnt the change get reflected
> in main.
> isnt is similar to passing an array?
> Enlighten me in this regard. I am tired of segfaults :(
>
> Regards,
> S.Nishaanth,
> Computer Science and engineering,
> IIT Madras.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to