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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:50:20+00:00 2026-05-30T07:50:20+00:00

In Cprogramming.com I found this piece of code: int a,b; scanf(%d %d,&a,&b); b=(a+b)-(a=b); printf(%d

  • 0

In Cprogramming.com I found this piece of code:

int a,b;
scanf("%d %d",&a,&b);
b=(a+b)-(a=b);
printf("%d %d",a,b);

It is claimed to be a tip/trick to “swap without using temporary”. My tests on Linux gcc prove it. However, wouldn’t the order how different compilers or platforms computing this expression matters here? Is it safe to use such code?

  • 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-30T07:50:21+00:00Added an answer on May 30, 2026 at 7:50 am

    No. In the expression (a+b)-(a=b) there is no sequence point between a being written to and a being read in the (a+b) sub-expression to determine the value to be stored to b so the behaviour is undefined.

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

Sidebar

Related Questions

I'm trying to generate spotify playlists (not text-based) and found this on Github: https://github.com/liesen/spotify-api-server
I somehow found this webpage and was absolutely stunned by the navigation bar. www.webdesignerwall.com
This post is a duplicate from superuser.com, but since I had no answers, I
This very well my be a SuperUser.com question, however it's directly related to my
So this is IT more than programming but Google found nothing, and you guys
This is why I'm asking this question: Last year I made some C++ code
I found this on android developers when i was trying to program a button:
I've just started learning C++, and to display the outputs of code I found
In the OpenGL ES 2.0 introduction, found here: http://www.webreference.com/programming/opengl_es/2.html a vertex shader is defined:
I'm just starting to learn the C programming language. I've written this simple piece

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.