Explanation of C code on how answer was received.

Computer Science
Tutor: None Selected Time limit: 1 Day

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

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Dec 15th, 2014
...
Dec 15th, 2014
Feb 20th, 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