Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ pointer

#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;
}
Source by www3.ntu.edu.sg #
 
PREVIOUS NEXT
Tagged: #pointer
ADD COMMENT
Topic
Name
9+6 =