Arrays and Pointers

Discussion in 'C++' started by kieran@cyrocom.co.uk, Aug 27, 2005.

  1. Guest

    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
     
    , Aug 27, 2005
    #1
    1. Advertising

  2. Guest

    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
     
    , Aug 27, 2005
    #2
    1. Advertising

  3. David Hilsee Guest

    <> wrote in message
    news:...
    > 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
     
    David Hilsee, Aug 27, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kelvSYC

    Arrays and Pointers to Arrays

    kelvSYC, Sep 26, 2003, in forum: C Programming
    Replies:
    2
    Views:
    387
  2. Replies:
    1
    Views:
    655
    -berlin.de
    Mar 28, 2005
  3. Philipp
    Replies:
    21
    Views:
    1,134
    Philipp
    Jan 20, 2009
  4. Francesco
    Replies:
    2
    Views:
    1,113
    Francesco
    Nov 6, 2009
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    682
Loading...

Share This Page