“Cómo convertir la función MALLOC en CPP” Código de respuesta

Malloc en C

#include <iostream>
#include <cstdlib>
using namespace std;

int main() {

  // allocate memory of int size to an int pointer
  int* ptr = (int*) malloc(sizeof(int));

  // assign the value 5 to allocated memory
  *ptr = 5;

  cout << *ptr;

  return 0;
}

// Output: 5
piyush kant tripathi

Cómo convertir la función MALLOC en CPP

int *scratch = (int *)malloc(size * sizeof(int));

int* scratch = new int[size];
RX Legend

Respuestas similares a “Cómo convertir la función MALLOC en CPP”

Preguntas similares a “Cómo convertir la función MALLOC en CPP”

Más respuestas relacionadas con “Cómo convertir la función MALLOC en CPP” en C++

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código