Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Arrays and Pointers

Reply
Thread Tools

Arrays and Pointers

 
 
kieran@cyrocom.co.uk
Guest
Posts: n/a
 
      08-27-2005
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

 
Reply With Quote
 
 
 
 
annamalai.gurusami@gmail.com
Guest
Posts: n/a
 
      08-27-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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

 
Reply With Quote
 
 
 
 
David Hilsee
Guest
Posts: n/a
 
      08-27-2005
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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

--
David Hilsee


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
casting pointers/arrays to multidimensional arrays Francesco C++ 2 11-06-2009 09:04 AM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Learning pointers and arrays of pointers With Files ketema@gmail.com C Programming 1 03-28-2005 03:51 AM
Arrays and Pointers to Arrays kelvSYC C Programming 2 09-26-2003 06:52 AM



Advertisments