I have some misunderstanding about VS C++. In version 2010 the code below works fine: I can get a string and I can free memory afterwords.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define MAX 14
void GetString(char **str);
int main(int argc, char *argv[])
{
char *str = NULL;
GetString(&str);
printf("%s\n", str);
getchar();
free(str);
return 0;
}
void GetString(char **str)
{
char *s = (char *) malloc(sizeof(char) * MAX);
strcpy(s, "HELLO, WORLD!");
*str = s;
}
But in VS 2008 the code above will end up with memory corruption error. I guess, there is a small difference in standards used. Am I right? If no, could you, please, tell me, why the same code doesn't work in different versions of the Visual Studio?
Thank you beforehand for your answers.
p.s. I'm curious of what happens, but couldn't yet find any information on the topic.
p.p.s. Language used - C