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.
Can we create an array of pointers in C? Yes, we can.
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.
datatype *pointername [size]; For example, int *p[5]; It represents an array of pointers that can hold 5 integer element addresses.
Student** db = new Student*[5]; // To allocate it statically: Student* db[5];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With