In C (not C++)
what is the difference between:
function(int &a)
{
a = a + 2;
}
and:
function(int *a)
{
*a = *a + 2;
}
For what I understand they are the same no?
If there are differences can you explain them with examples?
In C (not C++)
what is the difference between:
function(int &a)
{
a = a + 2;
}
and:
function(int *a)
{
*a = *a + 2;
}
For what I understand they are the same no?
If there are differences can you explain them with examples?
int &a
is not code defined by the C standard and generally cannot be used in C. In C++, this declares a reference to an object, which is like a pointer but does not require *
when using the object that is pointed to, cannot be changed once created, and cannot use a null pointer.
For C++, differences between pointers and references are discussed here. In C, you cannot normally use int &a
. (It could be used in some hypothetical C implementation that supported it as extension, which is how C++ originated.)