C meaning of (++*ptr) pointer



In the previous topic we have studied Precedence of Value at and Address Operator of Pointer. In this chapter we will be looking more advance form of pointer. We are looking one step forward to learn meaning of (++*ptr) pointer

Meaning of (++*ptr) pointer

Meaning of (++*ptr) pointer Can be evaluated or drafted by implementing the below code snippet –

int num = 20 , *ptr ;
ptr = #
printf("%d",++*ptr);

Explanation : Meaning of (++*ptr) pointer

  1. ‘++’ and ‘*’ both are having equal precedence and priority. Associativity of these two operators is from right to left (Expression evaluated from R->L)
  2. Both the operators are Unary so they will only works on single operand
  3. Dereference operator ‘*’ will get chance for execution before pre increment operator ‘++’.

Re-Commanded Reference Article : Operator Precedence Table

Visual Understanding

meaning of Pointer ++*ptr

Calculation of Answer :

Consider that variable ‘num’ is stored at location address 3058 to which pointer ‘ptr’ is pointing so ‘ptr’ will have address of variable ‘num’

  ++*ptr     =  ++ ( *ptr )
             =  ++ ( *3058 )
             =  ++ ( 20 )
             =  21

* Operator will de-reference pointer to get value stored at that address.(i.e 20)

++ ( *3058 )
++ ( 20 )

Pre-increment on 20 will perform increment first then assignment

Program : Meaning of (++*ptr) Pointer

#include<stdio.h>

int main()
{
int n = 20 , *ptr ;
ptr = &n;
printf("%d",++*ptr);

return(0);
}

Output :

21

Re-commanded articles

In the next chapter we will be learning the meaning of (*++ptr) Pointer.