char ar[]
is only the same as char *ar
when ar
is a function parameter. Otherwise they are an array and a pointer respectively.
char ar[][]
is a 2-d array if ar
is not a function parameter. Otherwise it's a pointer to a 1-d array.
char *ar[]
is a 1-d array of pointers if ar
is not a function parameter. Otherwise it's a pointer to a pointer.
char **ar
is a pointer to a pointer.
Basically, if it's a function parameter and it looks like it's an array, it's actually a pointer to the array's first element. Arrays aren't passed in their entirety as function parameters. When you try to, you will pass pointers to first elements of the arrays, and not arrays themselves.
All variables defined outside of functions aren't neither in the heap nor on the stack. They are global variables.
All variables defined inside of functions (with the exception of static
variables) are on the stack. static
variables are global-ish, they aren't neither in the heap nor on the stack. static
reduces the visibility of a global variable to the function or module scope, only that.
Only those variables allocated explicitly via malloc()
, calloc()
, ralloc()
live in the heap. Some standard library functions may create variables/objects in the heap, e.g. fopen()
.