Connecting Tech Pros Worldwide Forums | Help | Site Map

basic data types

Paras Sharma
Guest
 
Posts: n/a
#1: Jul 19 '05
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


John Harrison
Guest
 
Posts: n/a
#2: Jul 19 '05

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


Closed Thread


Similar C / C++ bytes