You can see bellow my code where i try to understand how to use malloc. But, i do not understand something. Why the output of A array is all zero? I thought that calloc does this "trick" and not malloc. Can anyone help me? thanks in advance!
Code:
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
int *A;
A = malloc(5);
if(A==NULL){
printf("Error in allocating space for A array!\n");
exit(1);
}else{
printf("Allocating space for A array succeed!\n");
}
// printing the array without any changes
for(i=0; i<5; i++){
printf("A[%d]: %d\n", i, A[i]);
}
printf("\n");
// made some changes
A[0] = 4;
// again printing the array
for(i=0; i<5; i++){
printf("A[%d]: %d\n", i, A[i]);
}
printf("\n");
return 0;
}