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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:20:45+00:00 2026-05-27T03:20:45+00:00

I recently got confused by the following c++ snippet: #include <cstdio> int lol(int *k){

  • 0

I recently got confused by the following c++ snippet:

#include <cstdio>

int lol(int *k){
  *k +=5;
   return *k;
}

int main(int argc, const char *argv[]){
  int k = 0;
  int w = k + lol(&k);
  printf("%d\n", w);
  return 0;
}

Take a look at line:

int w = k + lol(&k);

Until now I thought that this expression would be evaluated from left to right: take current value of k (which before calll to lol function is 0) and then add it to the result of lol function. But compiler proves me I’m wrong, the value of w is 10. Even if I switch places to make it

int w = lol(&k) + k;

the result would be still 10. What am I doing wrong?

Tomek

  • 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-27T03:20:46+00:00Added an answer on May 27, 2026 at 3:20 am

    This is because the parameters in an expression are not specified to be evaluated in any particular order.

    The compiler is free to execute either parameter k or lol(&k) first. There are no sequence points in that expression. This means that the side-effects of the parameters can be executed in any order.

    So in short, it’s not specified whether the code prints 5 or 10. Both are valid outputs.

    The exception to this is short-circuiting in boolean expressions because && and || are sequence points. (see comments)

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

Sidebar

Related Questions

I don't use C that much and I recently got confused about 2d array
I recently got a stray character between function definitions in an include file and
I recently got the following error in my web application. The page 'ControlName.ascx' cannot
recently got an issue when loading vs 2008, it displays this... can anyone tell
We recently got some data back on a benchmarking test from a software vendor,
I recently got into Java. I have a background in dynamic languages and I'm
I recently got my home PC upgraded to a quad-core CPU and 64-bit OS.
I recently got a shiny new development workstation. The only disadvantage of this is
I just recently got around to converting an old svn project to git. Everything
I've recently got the source-code on a application. When im trying to build 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.