Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7755659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:37:12+00:00 2026-06-01T12:37:12+00:00

I was revisiting pointers when I had this doubt. int *ptr; int arr[5] =

  • 0

I was revisiting pointers when I had this doubt.

int *ptr;
int arr[5] = {10,20,30,40,50};
ptr = &arr[0];

Now printf("Value: %d",*ptr); would print 10

if I do:

ptr++;
printf("Value: %d",*ptr);

the result would be: 20

Similarly if I do:

*ptr++;
printf("Value: %d",*ptr);

the result is: 30

But

printf("Value: %d",++*ptr);

gives me 31

I thought since ptr is of type int when I increment it, it would jump 4 bytes to the next memory location. But why does it show the same behavior for *ptr++ and ptr++ and not for ++*ptr?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:37:13+00:00Added an answer on June 1, 2026 at 12:37 pm

    The first snippet is obvious: it prints what ptr points to, i.e. 10.

    The second one, moves the pointer forward of one element, which then points to the next element, i.e. 20.

    The third snippet is exactly the same as the previous one, because its first instruction increments the pointer and returns the unincremented value, which is dereferenced, but its result is discarded; what is dereferenced in the printf is the incremented pointer, which now points to 30.

    The last snippet is different: ++*ptr is ++(*ptr); *ptr dereferences ptr (which already points to 30), yielding 30, and ++ increments such value, which becomes 31.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one has bugged me for a while now. Recently when revisiting some code
Revising for php and cant seem to get this to print the values out
I'm revisiting this after a few weeks, because I could never get it to
This user asked a similar question but had no viable solution in the answers,
I'm revisiting a question ( How to test if numeric conversion will change value?
I'm revisiting and re-implementing the code that caused me to ask this question about
Revisiting this in case someone has a suggestion: I've been asked to either create
I am revisiting this code I made a year ago with the help of
I need some help revising this. It keeps only displaying 0s as the temp.
I'm revising the navigation of my news system and would like to do so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.