You are not logged in. Please login at www.codechef.com to post your questions!

×

why does passing a single pointer to a struct with a struct node* element in it not copy the pointers pointing location by value?

if i have struct node { int data; struct node* next; }; and if i pass a pointer struct node* ptr; which is pointing to a memory location of struct type and if i pass this pointer to a function,say fn(struct node* ptr); and modify the ptr->data part inside the fnt,then why isnt this change reflected when i return from the function...so my basic question is why is it behaving like i passed the data by value although i actually passed it using a pointer... the issue is resolved if i use a double pointer. but i am curious to know why it doesnt work for a single pointer

asked 11 Oct '13, 18:37

imcode's gravatar image

0★imcode
49203136
accept rate: 0%


Your function calling is right, and data in structures can be changed using functions. But as you are saying you are having problem, can you share your code using ideone in which you are getting this type of problem..?

I think you can refer this to get your doubt solved. :)

link

answered 11 Oct '13, 21:45

skbly7's gravatar image

2★skbly7
1.9k91724
accept rate: 8%

edited 11 Oct '13, 22:21

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,491
×62

question asked: 11 Oct '13, 18:37

question was seen: 764 times

last updated: 11 Oct '13, 22:21