C
csnerd
I have a really simple question.
What is the difference between allocating memory following way:
#1
int main(int argc,char* argv)
{
char str[strlen(argv[1])+1];
return 0;
}
vs.
#2
int main(int argc,char* argv)
{
char* str=malloc(strlen(argv[1])+1);
return 0;
}
Both code compiles fine on a Linux machine, but code #2 fails with
visual C++ compiler.
Is the code #1 not safe??? or there is not a huge difference between
the code and it is just a compiler issue? ( I understand that in code
#2 the memory is located on heap as oppose to the code #1)
Any help, regarding this would be greatly appreciated!
What is the difference between allocating memory following way:
#1
int main(int argc,char* argv)
{
char str[strlen(argv[1])+1];
return 0;
}
vs.
#2
int main(int argc,char* argv)
{
char* str=malloc(strlen(argv[1])+1);
return 0;
}
Both code compiles fine on a Linux machine, but code #2 fails with
visual C++ compiler.
Is the code #1 not safe??? or there is not a huge difference between
the code and it is just a compiler issue? ( I understand that in code
#2 the memory is located on heap as oppose to the code #1)
Any help, regarding this would be greatly appreciated!