Last active
August 29, 2015 14:07
-
-
Save mamaz/05e2df17e2ce8222fd82 to your computer and use it in GitHub Desktop.
initString.cpp simple pass by reference
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; | |
/** | |
User refrence sign '&' to make it pass by refernce. | |
*/ | |
void initString(char* &dest) { | |
dest = new char[255]; | |
dest[0] = 'a'; | |
dest[1] = 'b'; | |
dest[2] = '\0'; | |
cout << dest[1]; | |
} | |
int main() { | |
char *p; | |
initString(p); | |
cout << p[0]; | |
delete p; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment