Explanation of C code on how answer was received.

label Computer Science
account_circle Unassigned
schedule 1 Day
account_balance_wallet $5

void func2m() {

   int a[]={4,7,3,23,54,67,34,12,24,78};

int*i=a;

i +=2;

i -=1;

i+=5;

i -=2;

i +=3;

printf("%i", *i);

}

answer is 12.  I don't know how 12 was received. Please explain a step by step process on how this was achieved. Thanks!

Dec 15th, 2014

int main(int argc, constchar * argv[]) {

    int a[]={4,7,3,23,54,67,34,12,24,78};

    int*i=a; // initilizes pointer to start of a,

    printf( "Value of i: %i\n", *i); //prints the value at the location of pointer i

    i +=2; // shifts the pointer 2 values to the right

    printf( "Value of i: %i\n", *i);//prints the value at the location of pointer i

    i -=1; // shifts the pointer one value to the left

    printf( "Value of i: %i\n", *i);//prints the value at the location of pointer i

    i+=5;  // shifts pointer five to the right

    printf( "Value of i: %i\n", *i);//prints the value at the location of pointer i

    i -=2; // shifts pointer two to the left

    printf( "Value of i: %i\n", *i);//prints the value at the location of pointer i

    i +=3; // shifts pointer three to the right

    printf( "Value of i: %i\n", *i); // prints the value located at that pointer

    printf("%i", *i);

   

}

Dec 15th, 2014

Did you know? You can earn $20 for every friend you invite to Studypool!
Click here to
Refer a Friend
...
Dec 15th, 2014
...
Dec 15th, 2014
Sep 22nd, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer