-
What is the output of this program?
#include <iostream>
#include <new>
using namespace std;
int main ()
{
int k, num;
int * ptr;
num = 3;
ptr= new (nothrow) int[num];
if (ptr == 0)
cout << "Error: memory could not be allocated";
else
{
for (k=0; k{
ptr[num] = 7;
}
for (k = 0; k < num; k++)
cout << ptr[num] << " ";
delete[] ptr;
}
return 0;
}
-
- 3
- 7
- 7 7
- 7 7 7
- None of these
Correct Option: D
As we had given k value as 3, It will print the 7 for three times.