1.

Which among the following is correct syntax to declare a 2D array using new operator?(a) char (*pchar)[10] = new char[][10];(b) char (pchar) = new char[][10];(c) char (*char) = new char[10][];(d) char (*char)[][10]= new char;The question was posed to me by my college professor while I was bunking the class.I would like to ask this question from New Operator topic in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct OPTION is (a) CHAR (*pchar)[10] = new char[][10];

The explanation is: The new operator usage to declare a 2D array requires a pointer and size of array to be declared. Data type and then the pointer with size of array. The left index can be left BLANK or any VARIABLE can be ASSIGNED to it.



Discussion

No Comment Found

Related InterviewSolutions