Greetings.
I seek assistance with gaining an understanding of structs in the case when they are passed as pointers to function. Below are code snippets to illustrate my points of contention:
Code:typedef struct stack_t Stack;
struct stack_t{
int * data;
int top; //points to top of the *data
}
I define & initialize the struct as follows:
It is as this point when I initialize the struct that my understanding of the subject leads me to attempt the following method, which results in compiler errors. The definition of init() is as follows:Code:Stack stk;
Stack * S = &stk;
init(S, 3);
Code:void init(Stack * S, int N){
int * stk = (int*)malloc(N*sizeof(int));
stk = &(S->data); //Causes error
S->top = -1;
}
Would greatly appreciate assistance with addressing the above concern.
Look forward to a prompt response.
Best regards,
wirefree101