1D Arrays
Fixed (on stack) and Dynamic (on Heap)array are treated exactly the same, accept declaration and allocation:
Allocation:For dynamic: For fixed: int * vec; int vec[100]; /* that’s it*/vec = (int*)malloc(sizeof(int)*100);
Access:vec[70] = 1; or:*(vec+70) = 1;
Initialization example:Inefficient:for (i=0;ii++) vec[i] = 0;int *ptr = vec;int *end = vec + 99; *end = 0; /* or end = vec+100 */while (ptr != end) *ptr++ = 0;
Passing to a functionFunction prototype:void foo(int *ptr); or void foo(int ptr[]);Function call: foo(vec);