Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
Output of ++*p++

Can anyone explain me the output.

#include<stdio.h>
int main() {
    int a[]={10,20,30};
    int *p=a;
    ++*p++;
    printf("%d  %d  %d  %d",*p,a[0],a[1],a[2]);
}

output is 20 11 20 30

Postfix incrementation has a higher precedence, so value of second index should have been incremented. Why is the value of first index incremented?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Due to operator precedence,

++*p++ is same as ++(*(p++)).

That is equivalent to:

int* p1 = p++; // p1 points to a[0], p points to a[1]
++(*p1);       // Increments a[0]. It is now 11.

That explains the output.

over 4 years ago · Santiago Trujillo Report

0

This is because the postfix operator returns the value before the increment. So the pointer is well incremented but the prefix operator still applies to the original pointer value.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!