I have a problem with this C program. I don't understand why even though i initialized my array with a malloc()
instruction, I am having the same size (4bytes) whatever is the second parameter i pass to my function initialize.
#include <stdio.h>
#include <stdlib.h>
typedef struct stack{
int size;
int *tab;
int top;
} stack;
void initialize(stack* st, int sizeArray);
int pop(stack* stack);
void push(stack* stack, int number);
int main(){
int sized;
stack S;
stack* ptr_S = &S;
printf("Enter the size of your stack please: \n");
scanf("%d", &sized);
//We send the pointer of the stack to initialise
initialize(ptr_S, sized);
printf("%d\t%d", S.size, S.top);
//printf("\nThe size of the array is: %d\n", sizeof(S.tab)/sizeof(int));
printf("\nThe size of the array is: %d\n", sizeof(S.tab));
pop(ptr_S);
return 0;
}
void initialize(stack* st, int sizeArray){
st->size = sizeArray;
st->top = 0;
st->tab = (int*)malloc(sizeof(int) * sizeArray);
}