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

  • SEARCH
  • Home
  • 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 6837635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:30:03+00:00 2026-05-26T23:30:03+00:00

Let us assume, int *p; int a = 100; p = &a; What will

  • 0

Let us assume,

int *p;
int a = 100;
p = &a;

What will the following code actually do and how?

p++;
++p;
++*p;
++(*p);
++*(p);
*p++;
(*p)++;
*(p)++;
*++p;
*(++p);

I know, this is kind of messy in terms of coding, but I want to know what will actually happen when we code like this.

Note : Lets assume that the address of a=5120300, it is stored in pointer p whose address is 3560200. Now, what will be the value of p & a after the execution of each statement?

  • 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-05-26T23:30:03+00:00Added an answer on May 26, 2026 at 11:30 pm

    First, the ++ operator takes precedence over the * operator, and the () operators take precedence over everything else.

    Second, the ++number operator is the same as the number++ operator if you’re not assigning them to anything. The difference is number++ returns number and then increments number, and ++number increments first and then returns it.

    Third, by increasing the value of a pointer, you’re incrementing it by the sizeof its contents, that is you’re incrementing it as if you were iterating in an array.

    So, to sum it all up:

    ptr++;    // Pointer moves to the next int position (as if it was an array)
    ++ptr;    // Pointer moves to the next int position (as if it was an array)
    ++*ptr;   // The value pointed at by ptr is incremented
    ++(*ptr); // The value pointed at by ptr is incremented
    ++*(ptr); // The value pointed at by ptr is incremented
    *ptr++;   // Pointer moves to the next int position (as if it was an array). But returns the old content
    (*ptr)++; // The value pointed at by ptr is incremented
    *(ptr)++; // Pointer moves to the next int position (as if it was an array). But returns the old content
    *++ptr;   // Pointer moves to the next int position, and then gets accessed, with your code, segfault
    *(++ptr); // Pointer moves to the next int position, and then gets accessed, with your code, segfault
    

    As there are a lot of cases in here, I might have made some mistake, please correct me if I’m wrong.

    EDIT:

    So I was wrong, the precedence is a little more complicated than what I wrote, view it here:
    http://en.cppreference.com/w/cpp/language/operator_precedence

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

Sidebar

Related Questions

let's assume I have this snippet of the code: void foo_for_foo( void some_function(int, int))
let's assume we have the following code: public class TestScope { private int a
Let's assume this class in C#: public class LimitedList<T> : List<T> { private int
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
Let's assume that I've got 2d array like : int[,] my_array = new int[100,
Let's assume we have the following class: public class tx_fct { int _ok; public
Let's say I have the following code... StringBuilder sb = new StringBuilder(); for (int
let assume we have string name = stackoverflow.com; how to convert this string int
Let us assume we have the two following classes: abstract case class MyParent(param: Int)
Let's assume we have the following structure: index.php config.inc.php \ lib \ lib \

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.