So I've created a pointer to make a new array with the calloc() function. I want to access the array from this pointer as an array, but I'm not sure how to do that. Basically I want the array my_array to be the same as the contents in the array starting at the *stack pointer.
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char*argv[])
{
int capacity=5, *stack;
int my_array[3];
stack=(int*)calloc(capacity, sizeof(int));
capacity++;
stack=(void*)(realloc)(stack, capacity*sizeof(int));
my_array[0]=*stack;
my_array[1]=5;
}
my_arrayis complete independent fromstack. You can copy a value from stack as you do but there is no fixed link between the two. By the way, it is not very clear what you want to do and why you want to do it.