I was wondering if there is any difference (in terms of syntax and performance) between a string defined like
char str[200];
and
char *str;
str = calloc(200, sizeof(char));
Are there differences in terms of usage? (for ex, one is not compatible with strncpy or something) And more importantly, are there differences in terms of performance?
EDIT: I understand that an array defined by char * and calloc can grow and shrink, but should I pick heap memory over stack memory or the other way around for any reason? That’s what I was really trying to ask.
char str[200]allocated in stack memory where ascalloc()allocates in heap memory.By nature of calloc(), it assigns 0 to all the bytes allocated by it.
Pls refer the following for stack and heap comparison
Which is faster: Stack allocation or Heap allocation
http://www.linuxquestions.org/questions/programming-9/stack-faster-than-heap-685004/
What and where are the stack and heap?