Created
January 8, 2015 20:51
-
-
Save YetAnotherMinion/5ef4c93988e4e2502c5f to your computer and use it in GitHub Desktop.
allocation using new intilaizers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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