Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 05:18 PM
Paras Sharma
Guest
 
Posts: n/a
Default basic data types

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

  #2  
Old July 19th, 2005, 05:18 PM
John Harrison
Guest
 
Posts: n/a
Default Re: basic data types


"Paras Sharma" <parsharm@cisco.com> wrote in message
news:3F3889D0.5000009@cisco.com...[color=blue]
> Hi
>
>
> Does compiler generates classes for basic data types also ?? or it is
> just same as calling malloc[/color]

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.
[color=blue]
>
>
> What is the difference bwt 1) ^ 2) ..
>
>
>
> 1 )
> char * c = new char ( 4 ) ;
> delete c ;[/color]

This creates a single char and initialises it with the value 4
[color=blue]
>
> 2 )
> char * c = new char [ 4 ] ;
> delete [] c ;
>[/color]

This creates 4 uninitialised chars.
[color=blue]
>
>
> Can we use delete [] c in first examples .[/color]

No.
[color=blue]
>
> thanks
> Paras
>[/color]

john


 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles