Answers for "static and dynamic memory in c++"

C++
0

dynamic memory in c++

#include <iostream>

int main()
{
  int* ptr = new int(5);
  
  int* arr = new int[3];
  arr[0] = 96;
  arr[1] = 45;
  arr[2] = 72;
  
  std::cout << *ptr << "\n";// output: 5
  
  for (int i = 0; i < 3; i++)
  {
    std::cout << arr[i] << " ";
  } // output: 96 45 72
}
Posted by: Guest on January-15-2022

Code answers related to "static and dynamic memory in c++"

Browse Popular Code Answers by Language