Array of pointers.

Array of pointers.

Question:
I need to pass an array of pointers to a class to a function. The function is: void myFunc(myClass *example[]); The problem is that I need to define the size of this array at run time. I know this is possible with a normal array. For example:

int *array;array = new int[size];where size is a variable.

Is it possible to set up an array of pointers in this way? If so how is it done?

Answer:
A pointer is simply an integer that is an address of a memory location. So an array of pointers is really no different than an array of integers.

The first change you must make is with the declaration of array. If you were allocating an array of integers, then the array variable would be a pointer to the (first) integer in the array. However, if you want to allocate an array of pointers to integers, then the array variable must be a pointer to the (first) pointer to an integer in the array.

int **array;
Then you can use new as you did before, except the array data type is now integer pointers instead of just integers.
array = new int*[size];
It is very important to note that this does not allocate memory where those pointers will point. It only allocates the array of the pointers.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes