deleting a char array with cast to char*?

Which of these should be used?

char *ex = new char[255];
// code
delete [] ex;

or

char *ex = new char[255];
// code
delete [] (char *) ex;

I'm thinking that the cast isn't necessary, but would it have any effect on the actual deletion?

Answers


char *ex = new char[255];
// code
delete [] ex;

You do not need to cast, The cast won't have any effect anyways.

The C++ Standard does not need you to do any casting. Here is the reference.

Section ยง3.7.3.2.3:

The value of the first argument supplied to one of the deallocation functions provided in the standard library may be a null pointer value; if so, the call to the deallocation function has no effect. Otherwise, the value supplied to operator delete(void*) in the standard library shall be one of the values returned by a previous invocation of either operator new(size_t) or operator new(size_t, const std::nothrow_t&) in the standard library, and the value supplied to operator delete[](void*) in the standard library shall be one of the values returned by a previous invocation of either operator new[](size_t) or operator new[](size_t, const std::nothrow_t&) in the standard library.


It is not necessary and would have no effect. You are casting a char* to a char*.


Need Your Help

Disable firefox save as dialog-selenium

python firefox selenium

I am web scraping with selenium and whenever i try to download i file the firefox download/save as file pops up however, even If i apply profile.set_preference('browser.helperApps.neverAsk.saveToDi...

Positionning overflow content under fixed header and between fixed sidebars

css position overflow fixed

I'm trying to design a site with a fixed header and fixed sidebars, on a 100% height body.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.