Hi,
I'm playing around with pointers and I found out something.
For example, I have the array of objects of structure, and wished to point to it over the pointer which already points to it ( pointer to pointer to array of objects. ).
Confusing? Code:
struct person{int number;};
int main()
{
person object[3];
for(int j=0;j<4;j++){ //Just filling variable number
object[j].number=j+1;
cout<<(object[j].number=j+1)<<endl;
}
person *pobject; //Declaring pointer to object
pobject=object;
for(int i=0;i<4;i++){ //Checking how does it point (good/bad)
cout<<(pobject[i].number)<<endl;
}
person **pobject1[3]; //Declaring new pointer
pobject1[0]=&pobject;
for(int j=0;j<=5;j++){ //Printing variable number
for(int i=0;i<=5;i++){
cout<<(pobject1[i][j]->number)<<endl;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
I wished to create the array of objects of structure which will have variable number defined and create pointer to it ( which works great ), and afterwards create new pointer which'd point to existing one.
I realized if I pointed by this way:
pobject[0]=&pobject;
I'd have to use 2D array to represent variable number iterating by pointer.
I have no idea how does it work.
It just prints first variable number from first object and crashes.
Any help?
Thanks.