Reputation: 1917
I am not great on pointers but I have to learn in the field. If my understanding serves me correct these should all be valid statements below.
int* a;
int b = 10;
a = &b;
(*a) = 20;
(*a) == b; //this should be true
if you have a function like this:
void copy(int* out, int in) {
*out = in;
}
int m_out, m_in;
copy(&m_out, m_in);
m_out == m_in; // this should also be true
but I saw a function like this
create(float& tp, void* form, char* title);
I understand the void pointer, it can be cast to anything, I understand the character pointer which is basically a c style string.
I do not understand the first argument, which is the address of some type, let's say a float but it could be anything, a struct, a int, etc.
What is going on there?
Upvotes: 2
Views: 3666
Reputation: 777
The first argument is a reference, it just means that if you modify this field in your function create
, the field will still remain modified (even in the function where you called create()
) because it points to an address and not a value.
Upvotes: 0
Reputation: 28654
First this
int m_out, m_in;
copy(&m_out, m_in);
is undefined behaviour - you passed uninitialized vaiable m_in
to function - and hence trying to make copy of an uninitialized variable.
This:
create(float& tp, void* form, char* title);
doesn't make sense in C. Looks like reference from C++.
Upvotes: 9