Last active
August 29, 2015 13:56
-
-
Save hiepnd/9303658 to your computer and use it in GitHub Desktop.
Never trust a C++ function that return char *
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> | |
/** | |
* You can run online at http://code.hackerearth.com/ | |
*/ | |
using namespace std; | |
const char *doubleString(const char *s){ | |
string ss = string(s) + string(s); | |
return ss.c_str(); | |
} | |
int main() { | |
const char *hello = "hello"; | |
const char *hellox2 = doubleString(hello); | |
cout << "It should be \"" << hello << hello << "\"" << " actual: " << hellox2 << endl; | |
doubleString("dummy"); | |
cout << "It should be \"" << hello << hello << "\"" << " actual: " << hellox2 << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment