Skip to content

Instantly share code, notes, and snippets.

@asa55
Created April 3, 2020 20:54
Show Gist options
  • Save asa55/d63a5eef3595a4ce1ad748b5414b3de0 to your computer and use it in GitHub Desktop.
Save asa55/d63a5eef3595a4ce1ad748b5414b3de0 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
struct vector3 { float x, y, z; }; // struct or class, doesn't matter
int main() {
int value = 5; // allocated on the stack
int array[5];
vector3 vector;
array[0] = 1;
array[1] = 2;
array[2] = 3;
array[3] = 4;
array[4] = 5;
int* hvalue = new int; // allocated on the heap (new gives this away)
*hvalue = 5;
int* harray = new int[5];
vector3* hvector = new vector3;
harray[0] = 1;
harray[1] = 2;
harray[2] = 3;
harray[3] = 4;
harray[4] = 5;
delete hvalue;
delete[] harray;
delete hvector;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment