Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 2
    +1 "Different syntax, same meaning." .. So the same thing, as the meaning matters more than the syntax. Commented Feb 10, 2010 at 3:51
  • Not true. By calling void func(int* ptr){ *ptr=111; int newValue=500; ptr = &newvalue } with int main(){ int value=0; func(&value); printf("%i\n",value); return 0; } , it prints 111 instead of 500. If you are passing by reference, it should print 500. C does not support passing parameter by reference. Commented Feb 24, 2013 at 4:39
  • @Konfle, if you are syntactically passing by reference, ptr = &newvalue would be disallowed. Regardless of the difference, I think you are pointing out that "same meaning" is not exactly true because you also have extra functionality in C (the ability to reassign the "reference" itself). Commented Feb 24, 2013 at 15:21
  • We never write something like ptr=&newvalue if it is passed by reference. Instead, we write ptr=newvalue Here is an example in C++: void func(int& ptr){ ptr=111; int newValue=500; ptr = newValue; } The value of the parameter passed into func() will become 500. Commented Feb 24, 2013 at 17:58
  • In the case of my comment above, it is pointless to pass param by reference. However, if the param is an object instead of POD, this will make a significant difference because any changed after param = new Class() inside a function would have no effect for the caller if it is passed by value(pointer). If param is passed by reference, the changes would be visible for the caller. Commented Feb 24, 2013 at 18:05