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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:03:15+00:00 2026-05-14T01:03:15+00:00

The associativity of stream insertion operator is rtl, forgetting this fact sometimes cause to

  • 0

The associativity of stream insertion operator is rtl, forgetting this fact sometimes cause to runtime or logical errors.
for example:

1st-

int F()
{
   static int internal_counter c=0;
   return ++c;
}

in the main function:

//....here is main()
cout<<”1st=”<<F()<<”,2nd=”<<F()<<”,3rd=”<<F();

and the output is:

1st=3,2nd=2,3rd=1

that is different from what we expect at first look.

2nd-
suppose that we have an implementation of stack data structure like this:

    //
    //... a Stack<DataType> class …… 
    //

    Stack<int> st(10);
    for(int i=1;i<11;i++)
       st.push(i);

cout<<st.pop()<<endl<<st.pop()<<endl<<st.pop()<<endl<<st.pop()<<endl;

expected output is something like:

10
9
8
7

but we have:

7
8
9
10

There is no internal bug of << implementation but it can be so confusing…
and finally[:-)] my question: is there any way to change associativity of an operator by overloading it?

do you think this could be not reverse? i mean is it possible to change order by modifying or changing an open source STL?

  • 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-14T01:03:15+00:00Added an answer on May 14, 2026 at 1:03 am

    The only things that are right-associative are the assignment operators. See §5.4 to 5.18 of the standard. The << operators are evaluated left-to-right or the messages would be backward in grammar, not in content. The content is due to side effects, which are unordered in C++ except (as Neil mentions) for “short-circuit” && and ||, and comma.

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

Sidebar

Related Questions

I was going through operator precedence section of php.net and came across this example
As we all know that Associativity of assignment operator is from right to left
What is associativity for an operator and why is it important?
Lots of commonly useful properties of functions have concise names. For example, associativity ,
In C operation associativity is as such for increment, decrement and assignment. 2. postfix
I'd like to collect data of L2 cache misses for different cache associativity settings
Ok this is only my second question, and it's quite a doozy. It's for
On http://groups.google.co.in/group/comp.lang.c/browse_thread/thread/bfb312ad902d94eb/74dcdcacce777679?lnk=gst&q=conditional+operator#74dcdcacce777679 There is an answer given for a question why (A%2==0)?A=0:A=1 gives error.
In the C99 standard, the expressions allow for precedence and associativity. Precedence is documented
Talking about the associativity of operators in C, I was wondering why there are

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.