Sunday, July 12, 2009

I dont understand pointer to pointer and structure in structure in c?

for whe use it ans whats the advantge

I dont understand pointer to pointer and structure in structure in c?
I assume that you know Pointers already. Now Pointer to Pointer means "A pointer holds the address of another another pointe". In C, C++ pointer to pointer is declared as





int *p; //simple pointer


int **q=%26amp;p //pointer to pointer





In practical situtation like O.S development programers required to handle memory(both RAM and HDD) frequently and mater of sense is not the value stored in memory but important is address of memory location. Therefore pointers to pointers are used. Pointer to pointer and structutre to structure mainly used in Data Structures like Linked Lists.





Structures are collection of disimilar datatypes.





eg:





struct employee


{


int empcode;


char ename[20];


float salary;


};








struct manager


{


struct emoplyee;


char dept[20];


}
Reply:It used to be that using pointers was an economical use of memory in C programming. These days it's less important and using a regualr variable can save you a lot of grief. There used to be saying in C programmer circles that "using pointers allows you to shoot yourself through the foot, using pointer to pointer structures allows you to shoot yourself through the foot and not know which foot". Example, colleague of mine was programming a small text editor in C and spent 3 days trying to get a a p2p structure to work. After virtually offering him violence (he'd been indoctrinated into pointers when he was learning C programming) I persuaded him to use a regular variable and he had his function sorted within 45 minutes.


No comments:

Post a Comment