Use new operator to allocate memory for char array : Char Array « Data Type « C++






Use new operator to allocate memory for char array

   
#include <iostream>
using namespace std; 
int main(void) {
   char *pointer;

   do {
     pointer = new char[10000];

     if (pointer)
       cout << "Allocated 10,000 bytes\n";
     else
       cout << "Allocation failed\n";
   } while (pointer);
}
  
    
    
  








Related examples in the same category

1.use char array as string
2.use getline to read char array based string
3.Use cin.getline to read a char array based string
4.Char array and char pointer