Originally Posted by
vohu
Hello,
I have a question : in C language, can we pass value by reference, as we do in C++ language ?
Formally no, because C has pointers -- most languages that use pointers do not use references and vice versa.
Pointers provide more functionality than references but are slightly more complicated to use, which is why C++ incorporated references.
Code:
// with pointers
void myfunc (int *x); // prototype
int n;
myfunc(&n); // call
// with references
void myfunc (int &x); // prototype
int n;
myfunct(n);
The second style is simpler and less prone to error. Because pointers allow you to do things you cannot do with a reference (such as arithmetic with memory addresses), where this functionality is undesirable, a reference would be considered "safer".