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 9266883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:25:14+00:00 2026-06-18T14:25:14+00:00

I found this code in a book: #include <iostream> using namespace std; void ChangesAreGood(int

  • 0

I found this code in a book:

#include <iostream>
using namespace std;

void ChangesAreGood(int *myparam) {
    (*myparam) += 10;
    cout << "Inside the function:" << endl;
    cout << (*myparam) << endl;
}

int main() {
    int mynumber = 30;
    cout << "Before the function:" << endl;
    cout << mynumber << endl;

    ChangesAreGood(&mynumber);
    cout << "After the function:" << endl;
    cout << mynumber << endl;

    return 0;
}

It says:

(*myparam) += 10;

What difference would the following produce?

*myparam += 10;
  • 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-18T14:25:15+00:00Added an answer on June 18, 2026 at 2:25 pm

    To answer your question:

    In your example, there is no difference except in readability.

    And, as the comments on this post all suggest, please don’t use the parenthesis here…

    Interesting other cases

    Using a property/method on the dereferenced object

    On the other hand, there is a difference if you have something like

    *myObject.myPropertyPtr += 10
    

    compared to

    (*myPointer).myProperty += 10
    

    The names I chose here tell you what the difference is: the dereference operator * works on whatever is on its right hand side; in the first case the runtime will fetch the contents of myObject.myPropertyPtr, and dereference that, while in the second example it will dereference myPointer, and get myProperty from whatever is found on the object that myPointer points to.

    The latter is so common that it even has its own syntax: myPointer->myProperty.

    Using the ++ operator rather than +=

    Another interesting example, which I thought of after reading another (now deleted) answer to this question, is the difference between these:

    *myPointer++
    (*myPointer)++
    *(myPointer++)
    

    The reason this is more interesting is because since ++ is a call like any other, and particularly doesn’t deal with left and right hand side values, it is more ambiguous than your examples with +=. (Of course, they don’t always make sense – sometimes you will end up trying to use the ++ operator on an object that doesn’t support it – but if we limit our study to ints, this won’t be a problem. And it should give you a compiler error anyway…)

    Since you caught my curiosity, I conducted a small experiment testing these out. This is what I found out:

    • *myPointer++ does the same thing as *(myPointer++), i.e. first increment the pointer, then dereference. This shouldn’t be so surprising – it is what we’d expect knowing the result of running *myObject.someProperty.

    • (*myPointer)++ does what you’d expect, i.e. first dereference the pointer, then increment whatever the pointer pointed to (and leave the pointer as is).

    Feel free to take a closer look at the code I used to find this out if you want to. Just save it to dereftest.cpp, compile with g++ dereftest.cpp -o dereftest (assuming you have G++ installed) and run with ./dereftest.

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

Sidebar

Related Questions

I found this code on internet : Class Book{ Public: void operator()(int Counter) const
I found this code using Google. private int RandomNumber(int min, int max) { Random
I found this code in The C Answer Book. int readline(char s[], int lim)
I have found this piece of code in a book: void DeleteList(element *head) {
i found this code -(NSString *) genRandStringLength: (int) len { NSMutableString *randomString = [NSMutableString
i found this code: protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); HwndSource hwndSource =
I'm trying to learn OpenGL. I tried some code I found in this book
I am learning Collections in CoreJava book and I found this code: List<String> a
I was reading opengl es book and in the source code i found this
From Accelerated C++ (book), I found this code which is identical program, but the

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.