Friday, 16 April 2010

Write a program to show same pointer can point to different data variables in different statements

/*    This program shows how the same pointer can point to different data variables in different statements. */
#
include < stdio.h >

    int main(void) {
        //    Local Declarations
        int a;
        int b;
        int c;
        int * pMult;

        //    Statements
        printf("Enter three numbers and key return: ");
        scanf("%d %d %d", & a, & b, & c);
        pMult = & a;
        printf("%3d\n", * pMult);
        pMult = & b;
        printf("%3d\n", * pMult);
        pMult = & c;
        printf("%3d\n", * pMult);
        return 0;
    } // main

/*    Results
Enter three numbers and key return: 10 20 30

 10
 20
 30
*/


No comments:

Post a Comment