I am trying to trace a code to practice for my upcoming test. I usually print the steps to find how the values are getting updated but for my current code, I can't do that. Would anyone mind helping me understand the tracing??
#include <stdio.h>
#include <stdlib.h>
void print(int *info, int size)
{
int i,*data,*dataptr;
for (i=0; i<size; i++)
printf("info[%d]=%d\n",i,info[i]);
printf("\n");
return;
}
int main()
{
int i,*data,*dataptr;
data = (int *)malloc(4*sizeof(int));
for (i=0; i<4; i++)
data[i]=3*i;
print(data,4); //output: 0 3 6 9 <-I understand this output
*data = 5; //I get
dataptr = data;//
dataptr++; //
*dataptr = 1;//
print(data,4); //output: 5 1 6 9
*(data+2) = 4;
*(dataptr+2)=2;
print(data,4);//output: 5 1 4 2
free(data);
return 0;
}