Understanding of pointers with malloc and free
Pointers are a really tricky thing in C. For a lot of people is hard to understand it, so for a good understanding I wrote following code: #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { int *p; // pointer -> will be dynamic allocated int *a; // array -> will be dynamic allocated // print before allocate memory (1) printf("&p: %p\tp: %p\t*p: %d\n", &p, p, *p); printf("&a: %p\ta: %p\t*a: %d\n", &a, a, *a); printf("\n"); // allocate memory (2) p = (int *)malloc(sizeof(int)); a = (int *)malloc(sizeof(int) * 10); // print after allocate, but before give a value to