Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ new

#include <iostream>

int main() 
{

	int* ptr = new int{};
    // creates null initialized pointer ptr
    
    delete ptr; // must be cleared manually
    

	// multiple memaddress allocation:

	int* p_arr = new int[5]{};
    /*
    new int[] returns the first elems pointer address
    {} initializes with default settings [int{} -> 0], such as MyObj()
    
    [5] -> can be var too, new functionality in modern cpp (new int[var_count])
    */
    
    delete[] p_arr;
}
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
7+2 =