I am expecting the following snippet to allocate memory for five members using calloc.
$ cat calloc.c // C program to demonstrate the use of calloc() // and malloc() #include <stdio.h> #include <stdlib.h> int main() { int *arr; arr = (int *)calloc(5, sizeof(int)); printf("%x\n", *arr); printf("%x\n", *(arr+1)); printf("%x\n", *(arr+2)); printf("%x\n", *(arr+3)); printf("%x\n", *(arr+4)); printf("%x\n", *(arr+5)); printf("%x\n", *(arr+6)); // Deallocates memory previously allocated by calloc() function free(arr); return(0); } But it seems to be allocating more than five; it is allocating six members, why?
./a.out 0 0 0 0 0 0 411
*(arr+3), you can just usearr[3]. It's 100% completely and totally equivalent.