I thought I understood the basic concepts of pointers according to the C tutorials, but I really get confused when I actually code. I have a few questions:
1 - Let's say I have:
customList arrayOfLists[3];
void someMethod()
{
int i;
for (i=0; i<3; i++)
{
customList l = arrayOfLists[i];
removeFirstElement(&l);
}
}
Why don't both Method 1 and Method 2 work the same? In both cases, I basically say delete the first element of the list located in addressX. Does it create a copy of the array?
2 - What is the difference between:
struct1.ptr1->ptr2->someIntValue
&(struct1).ptr1->ptr2->someIntValue
The second method does not make sense to me, and I do not know what is happening there, but it seems to work. I expected the first way of working, but this does not give me the correct answer.
3 - Suppose I do this:
ptr2 = ptrToStruct;
ptr1 = ptr2;
ptr2->intProp = 5;
ptr2 = ptrToStruct2;
Is ptr1 pointing to the original memory location, or is it the same ptr2? What is ptr1-> intProp?
Thank.
source
share