Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an array of pointers?

I am trying to create an array of pointers. These pointers will point to a Student object that I created. How do I do it? What I have now is:

Student * db = new Student[5]; 

But each element in that array is the student object, not a pointer to the student object. Thanks.

like image 987
chustar Avatar asked Mar 06 '09 23:03

chustar


People also ask

Can I create array of pointers in C?

Can we create an array of pointers in C? Yes, we can.

How do you create an array with 3 pointers?

char *ptr[3]; ==>it means ptr is an array of three character pointers. ptr[3] shows an element of an aray. char *ptr[3] is right because it is a declaration of pointer of array, i.e., *(*(ptr+i)) where i is a character type of variable, store the address of char array type variable.

What is array of pointers give an example?

datatype *pointername [size]; For example, int *p[5]; It represents an array of pointers that can hold 5 integer element addresses.


1 Answers

Student** db = new Student*[5]; // To allocate it statically: Student* db[5]; 
like image 57
mmx Avatar answered Oct 16 '22 15:10

mmx