#include #include void swap(int *x, int *y); int main(int argc, int *argv[]) { int x, y; // integer var 32 bits unsigned int ux; // unsigned integer char c; // one byte. short sx; int * px; // pointer to integer (address, allocated on stack) int * py; x = 3; y = 9; px = &x; // px set to address of x. *px = x+1; // same as x = x+1; x = *px + 1; // same as x=x+1; printf("%d\n",px); // prints address of x printf("%d\n",&y); // prints address of y printf("%d\n",*px); // prints contents at px px = px - 1; // px now points to next 32 bit word printf("%d\n",*px); // what should this print? printf("px-1 == %d\n",px); // what do you expect? px = ((char * ) px) - 1; printf("px as a char*: %d\n",px); // what do you expect? swap(&x,&y); printf("after swap: %d,%d\n",x,y); exit(0); } void swap(int *x, int *y) { int temp; temp = *x; *x = *y; *y = temp; } // call with swap(&a,&b). /* endian conversion program #include int main() { int x, y; int *z; char A[4]; scanf("%d",&x); z = &x; A[3] = ((char *)z)[2]; // 16 bits A[2] = ((char *)z)[3]; A[0] = A[1] = (char) 0; // A[3] = ((char *)z)[0]; // 32 bits // A[2] = ((char *)z)[1]; // A[1] = ((char *)z)[2]; // A[0] = ((char *)z)[3]; y = *((int *) A); printf(" y is %d\n",y); return 0; } */ /* linked lists: typedef struct listcell * cell; struct listcell { int head; cell tail; }; cell cons(int h, cell t) // make a list with head h and tail t { cell newcell; newcell = (cell) malloc(sizeof(struct listcell)); newcell->head = h; newcell->tail = t; return newcell; } */ /* generic polymorphic type: (void *) */