Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2013 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/6186317 to your computer and use it in GitHub Desktop.
Save anonymous/6186317 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
static const char* val1 = "hello";
const char* val2 = "hello";
const string val3 = "hello";
printf("\nbefore: %s, %s, %s", val1, val2, val3.c_str());
char* modifyingVal2 = const_cast<char*>(val1);
strcpy(modifyingVal2, "fuck");
printf("\nafter: %s, %s, %s, %s", val1, val2, val3.c_str(), modifyingVal2);
const char* stringChar = val3.c_str();
printf("\nafter: %p, %p, %p, %p", (void*)val1, (void*)val2, (void*)stringChar, (void*)modifyingVal2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment