Difference between ++*p, *p++ and *++p Last Updated : 02 Nov, 2022 Comments Improve Suggest changes Like Article Like Report Predict the output of following C programs. C // PROGRAM 1 #include <stdio.h> int main(void) { int arr[] = {10, 20}; int *p = arr; ++*p; printf("arr[0] = %d, arr[1] = %d, *p = %d", arr[0], arr[1], *p); return 0; } C // PROGRAM 2 #include <stdio.h> int main(void) { int arr[] = {10, 20}; int *p = arr; *p++; printf("arr[0] = %d, arr[1] = %d, *p = %d", arr[0], arr[1], *p); return 0; } C // PROGRAM 3 #include <stdio.h> int main(void) { int arr[] = {10, 20}; int *p = arr; *++p; printf("arr[0] = %d, arr[1] = %d, *p = %d", arr[0], arr[1], *p); return 0; } The output of the above programs and all such programs can be easily guessed by remembering following simple rules about postfix ++, prefix ++, and * (dereference) operators 1) Precedence of prefix ++ and * is same. Associativity of both is right to left. 2) Precedence of postfix ++ is higher than both * and prefix ++. Associativity of postfix ++ is left to right.(Refer: Precedence Table)The expression ++*p has two operators of same precedence, so compiler looks for associativity. Associativity of operators is right to left. Therefore the expression is treated as ++(*p). Therefore the output of first program is "arr[0] = 11, arr[1] = 20, *p = 11".The expression *p++ is treated as *(p++) as the precedence of postfix ++ is higher than *. Therefore the output of second program is "arr[0] = 10, arr[1] = 20, *p = 20 ".The expression *++p has two operators of same precedence, so compiler looks for associativity. Associativity of operators is right to left. Therefore the expression is treated as *(++p). Therefore the output of third program is "arr[0] = 10, arr[1] = 20, *p = 20". Comment More infoAdvertise with us Next Article Difference between ++*p, *p++ and *++p K kartik Follow Improve Article Tags : Difference Between C Language cpp-operator cpp-pointer C-Operators +1 More Practice Tags : cpp-operator Similar Reads Difference between int* p() and int (*p)()? A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, a pointer must be declare before storing any variable address. The general form of a pointer variable declaration is: Syntax: type *var_name; Here, type 2 min read Difference between x++ and x=x+1 in Java In x++, it increase the value of x by 1 and in x=x+1 it also increase the value of x by 1. But the question is that both are same or there is any difference between them. We should aware with the fact that whenever we are trying to apply any arithmetic operator between two variables a and b, the res 3 min read Difference Between '+' and 'append' in Python + Operator creates a new sequence by concatenating two existing sequences and .append() method (available for lists) modifies the existing list in place by adding one item at the end. In this article we are going to compare '+' operator and append in Python.+ Operator in Python+ operator is typicall 3 min read Difference between int *a and int **a in C In C, the declarations int *a and int **a represent two different concepts related to pointers. Pointers play a fundamental role in memory management and data manipulation in C programming so it is important to have a clear understanding of them. What does int * means? This declares a pointer to an 3 min read Difference between SOP and POS in Digital Logic In digital logic, the inputs and output of a function are in the form of binary numbers (Boolean values) i.e., the values are either zero (0) or one (1). Therefore, digital logic is also known as 'Boolean logic'. These inputs and output can be termed as 'Boolean Variables'. The output Boolean variab 5 min read Like