473,513 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cout, operator<<, sequence points

Hello,

I have a doubt about this operator, and I haven't found the answer in
internet (yet).
When calling the operator << several times in an expression, are all
parameters evaluated first and then passed to cout::<<, or are being
passed when they are evaluated ?
An example to clarify my question :

int foo()
{
cout << "calling foo";
return 1;
}

......
cout << "i = " << foo() << endl;

Should I see this:

calling fooi = 1

or

i = calling foo1 ??

Or is it undefined behaviour?

So going to the original question.... is "i=" passed to cout::<< first
and then foo() is evaluated and passed to cout::<<, or is foo()
evaluated and just then "i = " and foo() are passed to cout::<< ?? Or
undefined behaviour?

Thanks in advance,

Luis

Jul 23 '07 #1
1 1432
Victor, Jack, I really appreciate your answers, now it is also clear
to me.

Thanks a lot,

Luis
Jul 23 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1456
by: Sprite | last post by:
I write the following code int x1 = 5; std::cout<<x1--<<" "<<x1--<<" "<<x1; and got the result 4 5 3 in VS2003 who can explain that, THX
4
2047
by: bluekite2000 | last post by:
Here A is an instantiation of class Matrix. This means whenever user writes Matrix<float> A=rand<float>(3,2);//create a float matrix of size 3x2 //and fills it up w/ random value cout<<A; the following will be printed A 3 2
12
6072
by: Filipe Sousa | last post by:
Hi! Could someone explain to me why this operation is not what I was expecting? int main() { int x = 2; std::cout << x << " " << x++ << std::endl; return 0; }
3
1864
by: subramanian100in | last post by:
Consider the code: #include <iostream> using namespace std; int main( ) { cout << "test string "; cout.operator<<(10).operator<<(endl);
46
3352
by: suresh | last post by:
Hi, For this code snippet, I get the following output, which I am unable to understand. (2^31 = 2147483648) cout<< -2147483648 << endl; cout << numeric_limits<int>::min() <<',' << numeric_limits<int>::max()<< endl;
5
2449
by: Alex Vinokur | last post by:
void foo (int n) { std::ostringstream oss; oss << "ABCD: " << n << std::endl; std::cout << oss.str() << std::flush; } That function has been invoked in multiprocessing mode.
42
4468
by: barcaroller | last post by:
In the boost::program_options tutorial, the author included the following code: cout << "Input files are: " << vm.as< vector<string() << "\n"; Basically, he is trying to print a vector of string, in one line. I could
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7563
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5703
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3252
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.