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

87
Views
Pointer Array in C?

Pointers are a difficult topic for sure, but I have come across this snippet and I just can't figure out what the p[-1] is:

#include <stdio.h> 
int main(void) { 
    int t[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, *p = t; 

    p += 2; 
    p += p[-1]; 
    printf("%d",*p); 
    return 0; 
}
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Any time you see an expression like a[b] in C, you can mentally think that *(a + b) is happening.

So, it's just "the contents of the element before the one p is pointing at right now".

Since p is at t + 2, p[-1] refers to t[2 + (-1)] i.e. t[1].

over 4 years ago · Santiago Trujillo Report

0

p += p[-1]; 

can be written as

p = p + *(p-1);

At that point, p points to the 3rd element of the array (value 3) and *(p-1) is 2.

So, it's equivalent to

p = p+2;

and printing *p would print 5.

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!