Link to home
Start Free TrialLog in
Avatar of zoollu
zoolluFlag for Canada

asked on

Difference betweeen char[] and char* = new char[]

Hi,
I come from java background so this is confusing for me. When allocating dynamic memory in cplusplus what is the difference between allocating memory for char array using char var[40] and char* var = new char[40]?

How do I delete/free the allocated memory of char arrays in both forms?

thanks in advance.
 
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zoollu

ASKER

So can i allocate memory like

char var[sizeof(newitem)+30] and not care about deleting it since its gone when out of scope?
>> char var[sizeof(newitem)+30]

That's ok.

>> and not care about deleting it since its gone when out of scope?

Exactly.


But you won't be able to change the size of the buffer at run time. It's fixed at compile time to sizeof(newitem)+30 chars.
Avatar of zoollu

ASKER

thanks