First, this line contains undefined behavior
print(++ptr,ptr--,ptr,ptr++,++ptr);
because it uses a variable that is part of an expression with side effect multiple times without reaching a sequence point.
In the code static keyword is used so i thought that each time it would take a different input.
Presence or absence of static
keyword makes no difference in this example, because the code never prints the value of the pointer, only the content of memory pointed to by that pointer.
You can remove undefined behavior by moving each expression with side effects to a separate line, like this:
static int arr[]={97,98,99,100,101,102,103,104}; // static can be removed
int *ptr=arr+1; // Start at index 1
printf("%d\n", *++ptr); // Move to index 2, prints 99
printf("%d\n", *ptr--); // Print 99, move to index 1
printf("%d\n", *ptr); // Print 98, stay at position 1
printf("%d\n", *ptr++); // Print 98, move to position 2
printf("%d\n", *++ptr); // Move to position 3, print 100
(demo)
Now the output is different (and correct):
99
99
98
98
100
This is the output that you should expect to have based on the semantic of the pre-increment/decrement and post-increment/decrement operators.