Connecting Tech Pros Worldwide Help | Site Map

basic data types

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 04: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, 04: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 Search this Thread
Search this Thread:

Advanced Search

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

Popular Articles

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 220,840 network members.