Which command properly allocates memory?
-
char *a=new char[20];
-
char a=new char[20];
-
char a=new char(20.0);
-
None of the Above
A
Correct answer
Explanation
Option A correctly uses the new operator to allocate a character array: char *a = new char[20]; allocates 20 chars and stores the pointer in a. Options B and C are wrong because they assign a pointer to a non-pointer char variable.