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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:29:19+00:00 2026-05-13T06:29:19+00:00

I just wrote the following line of code: if (++(data_ptr->count) > threshold) { /*…*/

  • 0

I just wrote the following line of code:

if (++(data_ptr->count) > threshold) { /*...*/ } // example 1

My intent is to increment the count variable within the data structure that data_ptr points to before making the comparison to threshold, and this line of code works.

If I had instead wanted to increment data_ptr before making the comparison, I would have written this:

if ((++data_ptr)->count > threshold) { /*...*/ } // example 2

Out of curiosity, I also tried this line of code:

if (++data_ptr->count > threshold) { /*...*/ } // example 3

And found that it behaves exactly the same as the first one.

First question: Why does example #3 work the same as example #1? Is it a matter of operator precendence? Something in the standard? I had to write a quick test program becuase the answer was not obvious to me.

Second question: Should I write this if statement differently? I could perform the increment first, on its own line, and then test the condition in order to avoid any possible confusion. Is this necessary, or are the first two examples obvious enough on their own?

  • 1 1 Answer
  • 1 View
  • 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-13T06:29:20+00:00Added an answer on May 13, 2026 at 6:29 am

    1) Precedence

    2) Preference

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

Sidebar

Related Questions

accidentally at work I wrote the following line of code: string x = (object)
I'm using the following code (System.Data.SQLite within VB.net): Dim SQLconnect As New SQLite.SQLiteConnection() Dim
I wrote the following: <html> <head> </head> <body> <input type=date /> </body> </html> Just
I just wrote some new utility methods within a non-page class for an existing
I just wrote some code to test the behavior of std::equal, and came away
Given the following piece of code: using(var data = new SomeDataContext(ConnectionString)) { data.ObjectTrackingEnabled =
I wrote the following code today to experiment with returning pointers to allocated memory.
I just wrote some C code: #include <stdlib.h> #include <time.h> #include <string.h> typedef struct
Is anyone aware of the reasons why the following line of T-SQL code works
I wrote the following code: int N; scanf(%d, &N); int i; for (i =

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.