c - Why doesn't *(ptr++) give the next item in the array? -


int my_array[] = {1,23,17,4,-5,100}; int *ptr; int i; ptr = &my_array[0];     /* point our pointer first                          element of array */ printf("\n\nptr = %d\n\n", *ptr); (i = 0; < 6; i++) {     printf("my_array[%d] = %d   ",i,my_array[i]);   /*<-- */     printf("my_array[%d] = %d\n",i, *(ptr++));        /*<-- b */ } 

why display same thing both line , b? displays of values in my_array in order (1, 23, 17, 4, -5, 100). why '++' in line b not point ptr next element of array before dereferenced? if change line

printf("ptr + %d = %d\n",i, *ptr++);        /*<-- b */ 

the output same. why this?

ptr++ increments ptr returns original value
++ptr increments , returns new value

hence joke c++ - it's 1 more c use original value = c


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -