Multiple choice technology programming languages

Which command properly allocates memory?

  1. char *a=new char[20];

  2. char a=new char[20];

  3. char a=new char(20.0);

  4. None of the Above

Reveal answer Fill a bubble to check yourself
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.