Skip to content

Instantly share code, notes, and snippets.

@YetAnotherMinion
Created January 8, 2015 20:51
Show Gist options
  • Save YetAnotherMinion/5ef4c93988e4e2502c5f to your computer and use it in GitHub Desktop.
Save YetAnotherMinion/5ef4c93988e4e2502c5f to your computer and use it in GitHub Desktop.
allocation using new intilaizers
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
char b = 'P';
char* c = new char('I');
char** d = new char*(new char('R'));
char** a = &c;
cout << *d << endl;
cout << b << endl;
cout << *a << endl;
//free this way
delete *d;
delete c;
delete d;
//old way
char bb = 'P';
char* cc = new char(0);
*cc = 'I';
char* t = new char(0);
*t = 'R';
char** dd = new char*(NULL);
*dd = t;
char** aa = &cc;
cout << *dd << endl;
cout << bb << endl;
cout << *aa << endl;
//free the easy way
delete cc;
delete t;
delete dd;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment