basic data types

Discussion in 'C++' started by Paras Sharma, Aug 12, 2003.

  1. Paras Sharma

    Paras Sharma Guest

    Hi


    Does compiler generates classes for basic data types also ?? or it is
    just same as calling malloc


    What is the difference bwt 1) ^ 2) ..



    1 )
    char * c = new char ( 4 ) ;
    delete c ;

    2 )
    char * c = new char [ 4 ] ;
    delete [] c ;



    Can we use delete [] c in first examples .

    thanks
    Paras
     
    Paras Sharma, Aug 12, 2003
    #1
    1. Advertising

  2. "Paras Sharma" <> wrote in message
    news:...
    > Hi
    >
    >
    > Does compiler generates classes for basic data types also ?? or it is
    > just same as calling malloc


    I think you mean does the compiler initialise built in types when calling
    new. The answer is maybe. In your example 1 below, the allocated char is
    initialised, in your example 2 the allocates chars are not inituialised.

    >
    >
    > What is the difference bwt 1) ^ 2) ..
    >
    >
    >
    > 1 )
    > char * c = new char ( 4 ) ;
    > delete c ;


    This creates a single char and initialises it with the value 4

    >
    > 2 )
    > char * c = new char [ 4 ] ;
    > delete [] c ;
    >


    This creates 4 uninitialised chars.

    >
    >
    > Can we use delete [] c in first examples .


    No.

    >
    > thanks
    > Paras
    >


    john
     
    John Harrison, Aug 12, 2003
    #2
    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. Kevin
    Replies:
    1
    Views:
    450
    Wibble
    Jun 12, 2005
  2. ramu
    Replies:
    2
    Views:
    346
    rlblaster
    Feb 20, 2006
  3. sandSpiderX
    Replies:
    20
    Views:
    713
    Lionel B
    Jun 27, 2005
  4. Gary Roach
    Replies:
    0
    Views:
    125
    Gary Roach
    Sep 1, 2013
  5. Fábio Santos
    Replies:
    0
    Views:
    140
    Fábio Santos
    Sep 4, 2013
Loading...

Share This Page