Skip to content

Instantly share code, notes, and snippets.

@mamaz
Last active August 29, 2015 14:07
Show Gist options
  • Save mamaz/05e2df17e2ce8222fd82 to your computer and use it in GitHub Desktop.
Save mamaz/05e2df17e2ce8222fd82 to your computer and use it in GitHub Desktop.
initString.cpp simple pass by reference
#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