edited by
602 views

1 Answer

2 votes
2 votes

*(ptr)++ is no different from *ptr++

The postfix and prefix operators always follow four steps.

  1. Make a copy of the variable
  2. Increment the copy of the variable
  3. Assign the incremented copy back to the original variable
  4. Prefix ++x returns the incremented variable, Postfix x++ returns the unincremented variable.
#include <stdio.h>

int main(void) {
    char *ptr = "gateforum";
    *ptr++; //ptr is incremented but while derefrencing non-incremented address is returned
    ptr++; //ptr is incremented and now pointing "t" in "gateforum"
    printf("%s",ptr++); //ptr is incremented but "teforum" is printed 
    return 0;
}

https://denniskubes.com/2012/08/14/do-you-know-what-p-does-in-c/

 

Related questions

0 votes
0 votes
1 answer
1