basic data types

P

Paras Sharma

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
 
J

John Harrison

Paras Sharma said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top