# Thread: need help on struct *pointer

1. ## need help on struct *pointer

I am a C newbie, and I really don't know what struct ** mean?
I have read many books but no books explain detail and clearly.
can anyone please explain what it mean?
for example:

struct student
{
int ID;
float GPA;
};

struct student **stu; /*is this mean an array of struct or it mean
a pointer to struct*/
also what does it different between struct * stu and struct**stu?

and when passing struct ** to a function what does it mean?
for example:
void searchStudent(int id, struct student **stud)
{
/*how to use struct student**stud here
does it imply an array of struct student? or a link list???
*/
}
Thank you very much for your help
C-IDIOT

http://pw2.netcom.com/~tjensen/ptr/cpoint.htm

It's a pretty good explanation

If you have
struct student
{
int ID;
float GPA;
};
struct student fred;

And you do
fred.ID = 1;

Then
struct student *ptr_to_fred = &fred;

And you do
ptr_to_fred->ID = 1;

Also
struct student **ptr_to_ptr_to_fred = &ptr_to_fred;

And you do
(*ptr_to_ptr_to_fred)->ID = 1;

> void searchStudent(int id, struct student **stud)
I imagine in this example, that you would want to update stud with the pointer to the student you found

struct student students[10];

Then somewhere in this function, when you had found the student you were looking for, you would do this
*stud = &students[i];

In the calling function, you would have something like this
struct student *found_stud;
searchStudent( 1, &found_stud );
printf( "Found = %d\n", found_stud->ID );

3. struct**, char**, int**, float**

can be used to create a dynamic array of either

struct*, char*, int*, float*

Eg.
Code:
```struct **array;           //can be resized dynamically
struct *array[10];      //cannot be resized```
By resizing the char**, you can add more and more elements.