Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

cpp malloc

int alloc_size = 10;
int* buffer = (int*) malloc (alloc_size);
//Allocate memory block which can fit 10 integers 
Comment

PREVIOUS NEXT
Code Example
Cpp :: if even number c++ 
Cpp :: c++ infinite for loop 
Cpp :: how to do (binary) operator overloading in c++ 
Cpp :: remove last character from string c++ 
Cpp :: c++ print vector without loop 
Cpp :: how to clear console c++ 
Cpp :: c++ length of char* 
Cpp :: difference between lower and upper bound 
Cpp :: c++ reverse integer 
Cpp :: how to iterate from second element in map c++ 
Cpp :: how to write something in power of a number in c++ 
Cpp :: scan line in c++ 
Cpp :: convert all characters in string to uppercase c++ 
Cpp :: sort vector using marge sorting in c++ 
Cpp :: number of words in c++ files 
Cpp :: c++ simple car game 
Cpp :: change integer to string c++ 
Cpp :: c++ find_if 
Cpp :: overload stream extract cpp 
Cpp :: how to erase a certain value from a vector in C++ 
Cpp :: delete specific row from dynamic 2d array c++ 
Cpp :: 1523. Count Odd Numbers in an Interval Range solution in c++ 
Cpp :: c++ splitstring example 
Cpp :: cpp vector2 
Cpp :: how to find the size of a character array in c++ 
Cpp :: print octal number in c++ 
Cpp :: reverse level order traversal 
Cpp :: how to specify the number of decimal places in c++ 
Cpp :: string vector to string c++ 
Cpp :: gettimeofday header file 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =