J
Jonathan Bartlett
im very confused about using memcpy and i have three
It appears that you are confused on _pointers_ and not on memcpy.
memcpy takes two _pointers_ and copies the data from one set of memory
locations to another. If you don't understand what a pointer is or
does, you're screwed to start with.
Not using memcpy. TRUE doesn't exist anywhere in memory, therefore
memcpy would be unable to find it.
No, they won't both work. The first one is completely wrong. The
second one should work (of course, you should initialize them first :])
The first one has no pointer to the memory -- it just gets whatever
value is in a & b. If a & b are 1 and 27, it would try to copy the
_contents_ of memory location 1 into memory location 27, neither of
which have anything to do with the values or memory locations of a and b.
If you're having trouble with pointers, perhaps you should learn
assembly language -- I've found that learning assembly language makes
pointers a lot easier to understand. You can check out my assembly
language book in my sig.
Jon
questions....memcpy takes a pointer to src and a pointer to dest and
copies src to destination...but im very confuzed about when to use '&'
operator while using memcpy....i have code that use '&' and the code
that call memcpy without '&'
It appears that you are confused on _pointers_ and not on memcpy.
memcpy takes two _pointers_ and copies the data from one set of memory
locations to another. If you don't understand what a pointer is or
does, you're screwed to start with.
one more thing how can i use macros in memcpy
like if i have
#define TRUE 1
then how can i copy TRUE into s1->name.
Not using memcpy. TRUE doesn't exist anywhere in memory, therefore
memcpy would be unable to find it.
Moreover , if i copy two INTS as in
int a;
int b;
memcpy(a,b,sizeof(int));
memcpy(&a,&b,sizeof(int));
Though i have not tested above but as far as i remember both of the
above memcpy lines will compile and work..aint it koz of the reason
No, they won't both work. The first one is completely wrong. The
second one should work (of course, you should initialize them first :])
The first one has no pointer to the memory -- it just gets whatever
value is in a & b. If a & b are 1 and 27, it would try to copy the
_contents_ of memory location 1 into memory location 27, neither of
which have anything to do with the values or memory locations of a and b.
If you're having trouble with pointers, perhaps you should learn
assembly language -- I've found that learning assembly language makes
pointers a lot easier to understand. You can check out my assembly
language book in my sig.
Jon