Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C programming help Please! I need a tutor to help/explian to me to understading

ID: 2990058 • Letter: C

Question

C programming help

Please! I need a tutor to help/explian to me to understading : what is the values for the elements of the x array that are printed out by the program show below:

#include<stdio.h>

#define SIZE 6

void main(void)

{

int x[] = {-3,24,9,-32,0,213};

int i, *px;

px = x + 2?

?*px)++;

px++;

(*px++)--;

*px += 5;

for?i=0;px=x+1;i<SIZE/2;i++,px+=2)

(*px) *=2;

for(i=0;i<SIZE;i++)

printf("x[%d] = %d ", i, x[i]);

}

}

Please explian to me what's the output and help me understanind why? Thank you?

Explanation / Answer

#include<stdio.h>
#define SIZE 6
int main()
{
int x[] = {-3,24,9,-32,0,213};
int i, *px;
px = x+2; // px pointing to x[2].
(*px)++; // increment value of x[2] now x[2] = x[2]+1 = x[2] = 9+1 = 10.
px++; // increment pointer now px pointing to x[3].
(*px++)--; // increment pointer and decrement the value pointed by old px i.e x[3] = -32-1 = -33
*px += 5; // now px is pointing to x[4] now add 5 to x[4]. x[4] = 0+5 = 5.
for(i=0, px=x+1;i<SIZE/2; i++,px+=2) // px = x+1 px pointing to x[1] and incremnt by 2 ever time.
(*px) *=2; // x[1] = x[1] * 2 => x[1] = 24*2 = 48
           // x[3] = x[3] * 2= -33 * 2 = -66
           // x[5] = x[5] * 2 = 213*2 = 426.
for(i=0;i<SIZE;i++)
printf("x[%d] = %d ", i, x[i]); // print all values.
return 0;
}

/* OUTPUT
x[0] = -3
x[1] = 48
x[2] = 10
x[3] = -66
x[4] = 5
x[5] = 426
*/