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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:32:38+00:00 2026-05-13T23:32:38+00:00

Consider this code: void res(int a,int n) { printf(%d %d, ,a,n); } void main(void)

  • 0

Consider this code:

void res(int a,int n)
{
    printf("%d %d, ",a,n); 
}

void main(void) 
{
    int i; 
    for(i=0;i<5;i++)
        res(i++,i);
    //prints 0 1, 2 3, 4 5

    for(i=0;i<5;i++)
        res(i,i++);
    //prints 1 0, 3 2, 5 4
}

Looking at the output, it seems that the arguments are not evaluated from right to left every time. What exactly is happening here?

  • 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-13T23:32:38+00:00Added an answer on May 13, 2026 at 11:32 pm

    The order of evaluation of arguments in a function call is unspecified. The compiler can evaluate them in whichever order it might decide on.

    From the C99 standard 6.5.2.2/10 “Function calls/semantics”:

    The order of evaluation of the function designator, the actual arguments, and
    subexpressions within the actual arguments is unspecified, but there is a sequence point
    before the actual call.

    If you need to ensure a particular ordering, using temporaries is the usual workaround:

    int i; 
    for(i=0;i<5;i++) {
        int tmp = i;
        int tmp2 = i++;
    
        res(tmp2,tmp);
    }
    

    Even more important (since it results in undefined behavior, not just unspecified behavior) is that you generally can’t use an operand to the increment/decrement operators more than once in an expression. That’s because:

    Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored. (6.5/2 “Expressions”)

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

Sidebar

Related Questions

Consider this code: int main() { int e; prn(e); return 0; } void prn(double
I have a trouble with references. Consider this code: void pseudo_increase(int a){a++;} int main(){
Consider this code: class arraytest { public static void main(String args[]) { int[] a
Consider this code: class Jm44 { public static void main(String args[]){ int []arr =
Consider this code snippet: public static void main(String[] args) { int z1 = 0;
Consider this code snippet: class Program { static void Main(string[] args) { Console.WriteLine(Test().ToString()); }
consider this code snippet void make(int n) { std::string user_input; std::istringstream iss(user_input); char letter;
Consider this code: static void Main(string[] args) { var persons = new List<Person> {
Consider this code: class test { public static void main(String[] args) { test inst_test
consider this simple and pointless code. #include <iostream> struct A { template<int N> void

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.