In: Computer Science
Problem5: (5 pts)
using c programming
Given an array of integers named “simple” of length 8 and filled as follows:
5 |
20 |
13 |
8 |
0 |
16 |
55 |
2 |
int x = 5;
int *p = &simple[3] ;
Write the values of x after each of the following executes (write unknown if cannot be determined): (hint: pointer moves to new location after each line)
x = *(p++); x = ___8_______________ p->simple[4]
x = *( p + 1) ; x = _____16______________ p- simple[4]
x = simple[5] - *(p--); x = ____16___________ p->simple[3]
x = *(--p); x = _____13__________ p->simple[2]
x = simple[0] / simple[7]; x = ____2________
I am not understanding how he is coming up with these answers all the way. I think the *(p++) throws me off. just looking for explanations thank you
code:
#include<stdio.h>
int main(){
int simple[]={5,20,13,8,0,16,55,2}; //array
initialization
int x=5;
//initializing x
int *p=&simple[3];
//assigning address
x=*(p++);
printf("%d\n",x);
x=*(p+1);
printf("%d\n",x);
x=simple[5]-*(p--);
printf("%d\n",x);
x=*(--p);
printf("%d\n",x);
x=simple[0]/simple[7];
printf("%d\n",x);
}
explanation: