/* chlng.c * CS201 - by RA */ #include int main(void) {int result; int z=3, y=2, x=0; int * ptrC, * ptrB, * ptrA; /*what if we would write "int * ptrC, ptrB, ptrA;" instead? */ printf ("\nValues of x: %d, y: %d, z: %d",x, y, z); printf ("\nAddress of x: %p, y: %p, z: %p",&x, &y, &z); ptrA = &x; x++; //i.e. x = x + 1 printf ("\n\nAfter ptrA=&x and x++ are performed"); printf ("\nValue returned by *ptrA: %d, ptrA points at: %p",*ptrA, ptrA); ptrA++; printf ("\n\nAfter ptrA++ is performed"); printf ("\nValue returned by *ptrA: %d, ptrA points at: %p",*ptrA, ptrA); result= *ptrA++; // IMPORTANT to know what is going to be performed first! printf ("\n\nAfter result= *ptrA++ is performed"); printf ("\nValue returned by *ptrA: %d, ptrA points at: %p",*ptrA, ptrA); printf ("\nValue returned by result: %d",*ptrA); ptrB = ptrA - 2; printf ("\n\nAfter ptrB=ptrA-2 is performed"); printf ("\nValue returned by *ptrB: %d, ptrB points at: %p",*ptrB, ptrB); printf ("\nValue returned by *ptrA: %d, ptrA points at: %p",*ptrA, ptrA); ptrC = &(*ptrA); //the same as prtC=ptrA; printf ("\n\nAfter ptrC=&(*ptrA) is performed"); printf ("\nValue returned by *ptrC: %d, ptrC points at: %p",*ptrC, ptrC); printf ("\nValue returned by *ptrA: %d, ptrA points at: %p",*ptrA, ptrA); ptrC = ptrA; printf ("\n\nAfter ptrC=ptrA is performed"); printf ("\nValue returned by *ptrC: %d, ptrC points at: %p",*ptrC, ptrC); printf ("\nValue returned by *ptrA: %d, ptrA points at: %p",*ptrA, ptrA); *(ptrA--)=7; printf ("\n\nAfter *(ptrA--)=7 is performed"); printf ("\nValue returned by *ptrA: %d, ptrA points at: %p",*ptrA, ptrA); printf ("\nValue that was modified *(ptrA+1): %d, ptrA+1 points at: %p",*(ptrA+1), ptrA+1); *(--ptrA)=9; printf ("\n\nAfter *(--ptrA)=9 is performed"); printf ("\nValue returned by *ptrA: %d, ptrA points at: %p",*ptrA, ptrA); // ptrB= &ptrA; // warning: assignment from incompatible pointer type ptrB= (int *) &ptrA; printf ("\n\nAfter ptrB= (int *) &ptrA is performed"); printf ("\nValue returned by *ptrA: %d, ptrA points at: %p, address of ptrA: %p",*ptrA, ptrA, &ptrA); printf ("\nAddress we can retrieve using *ptrB: %p, ptrB points at: %p",*ptrB, ptrB); // ptrC= *ptrB; // warning: assignment makes pointer from integer without a cast ptrC= (int *) *ptrB; printf ("\n\nAfter ptrC= (int *) *ptrB is performed"); printf ("\nValue returned by *ptrA: %d, ptrA points at: %p, address of ptrA: %p",*ptrA, ptrA, &ptrA); printf ("\nAddress we can retrieve using *ptrB: %p, ptrB points at: %p",*ptrB, ptrB); printf ("\nValue we can retrieve using *ptrC: %d, ptrC points at: %p",*ptrC, ptrC); printf("\n"); exit(0); }