I was curious with this:
What is the diference between:
const int MAX_BUF = 1000; char* Buffer = malloc(MAX_BUF);
and:
char Buffer[MAX_BUF];
Case 1: In
Buffer is an array of size MAX_BUF. The allocation technique is called VLA.
Buffer
MAX_BUF
Case 2: In
Buffer is a pointer which is allocated a memory of size MAX_BUF which is 1000.
1000
and, an array is not the same as a pointer, and C-FAQ has a Very Good collection detailing the reasons.
The major difference, in terms of usability and behaviour are:
malloc()
free()
Note: Wiki
For example, the GNU C Compiler allocates memory for VLAs on the stack.
1.4m articles
1.4m replys
5 comments
56.9k users