#include #include //Ponters are variables which refer to the memory locations of other variables int main() { int cost = 5; int* cost_ptr; //Address of a chunk of memory for one or more integer(s) int i; //& operator: get the address at which the variable is stored. cost_ptr = &cost; //Let cost_ptr point to "cost" //* operator: get the contents of the address held in variable printf("Pointer = %d. Dereference = %d\n", cost_ptr, *cost_ptr); //Allocate a memory for 10 integers. Make "cost_ptr" be the address of allocated memory cost_ptr = (int*) malloc( 10 * sizeof(int)); //cost_ptr can be used as an array variable of multiple integers for (i = 0; i < 10; i++) { cost_ptr[i] = i*2; printf("value %d: %d\t", i, cost_ptr[i]); //You can also explicitly use the memory locatioin of ith integer. // You should probably not attempt this. *(cost_ptr + sizeof(int) * i) = 2*i ; printf("value %d: %d\n", i, *(cost_ptr + sizeof(int) * i)); } //Free the allocated mormory if you don't use it in the future free( cost_ptr); return 0; }