Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

malloc in 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
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #malloc
ADD COMMENT
Topic
Name
1+4 =