Use of new in C++

Discussion in 'C++' started by Krishna, Sep 29, 2004.

  1. Krishna

    Krishna Guest

    What is the differnce in these new operators

    char *a = new char[21];
    char *a = new char(21);

    Do the type of brac matter ?.. If yes what do they signify ?..
     
    Krishna, Sep 29, 2004
    #1
    1. Advertising

  2. "Krishna" <> wrote...
    > What is the differnce in these new operators
    >
    > char *a = new char[21];
    > char *a = new char(21);
    >
    > Do the type of brac matter ?.. If yes what do they signify ?..


    Yes, the first form allocates and array of 21 characters and returns
    a pointer to the first character. The second form allocates a single
    character and initialises it to 21.

    What book are you reading that doesn't explain this?

    V
     
    Victor Bazarov, Sep 29, 2004
    #2
    1. Advertising

  3. > What is the differnce in these new operators
    >
    > char *a = new char[21];
    > char *a = new char(21);
    >
    > Do the type of brac matter ?.. If yes what do they signify ?..


    They do matter. The first line allocates an array of 21 chars (and does not
    initialize it) while the second line allocates one char with initial value
    of 21.

    cheers,
    Marcin
     
    Marcin Kalicinski, Sep 29, 2004
    #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. Robb Smith
    Replies:
    2
    Views:
    584
    Saravana
    Jul 18, 2003
  2. =?Utf-8?B?UGF0cmljaw==?=

    Open new with new session

    =?Utf-8?B?UGF0cmljaw==?=, Dec 18, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    3,356
    tittlejoseph
    Sep 2, 2007
  3. =?Utf-8?B?Tm92aWNl?=
    Replies:
    2
    Views:
    6,689
    Alan Ferrandiz Langley
    Jun 9, 2004
  4. www
    Replies:
    30
    Views:
    3,045
    Adam Maass
    Oct 23, 2007
  5. Replies:
    2
    Views:
    485
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page