I have searched the web and found nothing regarding this..
char array[50];
char *array = new char[50];
Tell me the difference between them..
I have searched the web and found nothing regarding this..
char array[50];
char *array = new char[50];
Tell me the difference between them..
Mixing C/C++ is a nice though sometimes confusing:
char array[50];
Allocation on stack, so you don't need to worry about memory management. Of course you can use std::array<char, 50> array
which being C++ brings some advantages (like a method which returns its size). The array exists until you leave its scope.
char *array = new char[50];
Here you need to manage the memory, because it is kept in the heap until you free it. Important, you should use this whenever you want to remove it:
delete [] array;
There also exist free(array)
(Standard C) and delete
(without parenthesis). Never use those, whenever you use new someType[...]
.
Other that in both you still have a char array of 50 elements you can play with :-)