Arrays and Pointers

K

kieran

Hi,
I'm sorry for this question, as it probably has a really simple answer,
but say I have the following code:

std::string* strs[12];

Does this create a pointer to an array of strings, or does it create a
2 dimentional array of strings, or does it create an array of 12 string
pointers?
Thanks for your help,
Cheers,
Kieran
 
A

annamalai.gurusami

Hi,
I'm sorry for this question, as it probably has a really simple answer,
but say I have the following code:

std::string* strs[12];

Does this create a pointer to an array of strings, or does it create a
2 dimentional array of strings, or does it create an array of 12 string
pointers?

How about experimenting with simple programs to find out the answer?
Here is a sample program using int.

#include <iostream>

using namespace std;

int main()
{
int *fine[10];
int (*what)[10];

cout << sizeof(int*) << ", "
<< sizeof(fine) << ", "
<< sizeof(what) << endl;
}

The variable "fine" is an array of integer pointers, while the variable
"what" is a pointer to an array of integers.

Rgds,
anna
 
D

David Hilsee

Hi,
I'm sorry for this question, as it probably has a really simple answer,
but say I have the following code:

std::string* strs[12];

Does this create a pointer to an array of strings, or does it create a
2 dimentional array of strings, or does it create an array of 12 string
pointers?

It's an array of pointers. However, it could be used to create a "ragged
array", which is like a multidimensional array.

For a pointer to an array, see here:
http://www.eskimo.com/~scs/C-faq/q6.13.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top