C does not support call by reference, because when you pass the pointer then you are passing the address of the variable which is actually a value.
If a language is pass by reference, there are no different ways of passing the argument - you pass an argument and a reference is sent to the function - there are no syntactical differences between passing by value and passing by reference.
However, in C, when the intent is to pass by reference, then we change the syntax a bit - that is we don't pass the variable anymore, but pass the address of it. Technically speaking, the address is still copied to the parameter of the function and we use that copied address to dereference it and get the value stored at the address.
So, pointer is a tool to simulate/emulate call by reference, but the language as such does not naturally support call by reference. So, C is strictly call by value and not by reference.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.