0 votes 0 votes Now I suppose if i have a statement like *P++ then it is broken down as first (P++) and then *p (because both are unary operator and associtivity is right to left ) and if we have statement like a=*p++ then it is broken down into a=*p and then p is incremented !! Am i right ? Programming in C pointers programming-in-c + – spriti1991 asked Jun 1, 2015 spriti1991 684 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
2 votes 2 votes Postfix operator having higher priority than dereferencing operator. so P++ (dont increment P, use P value as it is . after whole operation increment it). Then a = *P Now P++.. Postfix is left to right associative while * is right to left. Digvijay Pandey answered Jun 1, 2015 Digvijay Pandey comment Share Follow See all 6 Comments See all 6 6 Comments reply spriti1991 commented Jun 1, 2015 reply Follow Share No they both have same priority and even associtivity is from right to left see this : http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm if you havent noticed in the first statemnt i havent put "assignment sign " and in second i have put . so now in both cases I want to know that my execution order (steps in which they are broken ) is in correct order or not ? !! 0 votes 0 votes Digvijay Pandey commented Jun 1, 2015 reply Follow Share Check again http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm Prefix and * having same priority and both are right to left.. But postfix having more priority than *, prefix as well and it is left to right associative.. 2 votes 2 votes spriti1991 commented Jun 1, 2015 reply Follow Share OOps my mistake any ways now i gt your answer but that would work in both case same ? Imagine to print a++ with a inital values as 4 and d= a++ Then first will give op as 5 and second would give d = 4 right (But next time whenever we are using"a" value will use 5 ) right ? 0 votes 0 votes Arjun commented Jun 1, 2015 reply Follow Share a++ returns the value of a and after this increments a. So whatever printed or assigned to another variable value will be the initial one. Next time we access a, its value will be previous value plus 1 and we are not allowed to access a, until this increment is sure to be done which are guaranteed at places called sequence points. 2 votes 2 votes spriti1991 commented Jun 1, 2015 reply Follow Share Okie got it ! Thanks sir :) 1 votes 1 votes Digvijay Pandey commented Jun 1, 2015 reply Follow Share 1.Int a = 4; Print ("%d", a++) Output will be 4. 2.Int a =4; d= a++ Print ("%d", d) Output will be 4. 3.Int a =4; d= a++ Print ("%d", a) Output will be 5.. In all above cases finally a value is 5 Only. 3 votes 3 votes Please log in or register to add a comment.
1 votes 1 votes Case 1: int a,b ; int *p =&b; b=9; printf("%d",*p++); Case 2: a=*p++; printf("%d",a); Both are giving op 9 only radha gogia answered Jul 23, 2015 radha gogia comment Share Follow See all 0 reply Please log in or register to add a comment.