Horje
dynamic memory allocation c++ Code Example
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
}
dynamic memory allocation c++
string* str_arr = nullptr;
str_arr = new string[10];

//initialize
str_arr[0] = "Hello";
str_arr[1] = " World!";




Cpp

Related
iteration in c++ Code Example iteration in c++ Code Example
function prototype c++ Code Example function prototype c++ Code Example
return function in cpp Code Example return function in cpp Code Example
batch to exe Code Example batch to exe Code Example
array c plus plus Code Example array c plus plus Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9