pre-decrement and post-increment issue [duplicate]
This question already has an answer here:
Undefined behavior and sequence points
5 answers
Unexpected order of evaluation (compiler bug?) [duplicate]
3 answers
Hi I am currently studying for my first exam in C++ programming and I am having this issue:
int x = 12;
int y = 2;
cout << x++ <<" "<< --x; //Output: 11 12
I expected the output to be: 11 11, because 'cout' goes from right to left so the pre-decrement on x (--x) should decrement the value of x, and x++ wouldn't print out 12 because it is post-decrement. Is this an example of undefined behaviour?
cout << x++ << " " << --y; //Output: 12 1
While this line outputs the expected value of x.
Thanks in advance.
c++ increment post-increment decrement pre-increment
marked as duplicate by CoryKramer
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 15:25
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Undefined behavior and sequence points
5 answers
Unexpected order of evaluation (compiler bug?) [duplicate]
3 answers
Hi I am currently studying for my first exam in C++ programming and I am having this issue:
int x = 12;
int y = 2;
cout << x++ <<" "<< --x; //Output: 11 12
I expected the output to be: 11 11, because 'cout' goes from right to left so the pre-decrement on x (--x) should decrement the value of x, and x++ wouldn't print out 12 because it is post-decrement. Is this an example of undefined behaviour?
cout << x++ << " " << --y; //Output: 12 1
While this line outputs the expected value of x.
Thanks in advance.
c++ increment post-increment decrement pre-increment
marked as duplicate by CoryKramer
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 15:25
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
"because 'cout' goes from right to left" nope, because you don't have any sequence points between those operations
– CoryKramer
Nov 15 '18 at 15:25
add a comment |
This question already has an answer here:
Undefined behavior and sequence points
5 answers
Unexpected order of evaluation (compiler bug?) [duplicate]
3 answers
Hi I am currently studying for my first exam in C++ programming and I am having this issue:
int x = 12;
int y = 2;
cout << x++ <<" "<< --x; //Output: 11 12
I expected the output to be: 11 11, because 'cout' goes from right to left so the pre-decrement on x (--x) should decrement the value of x, and x++ wouldn't print out 12 because it is post-decrement. Is this an example of undefined behaviour?
cout << x++ << " " << --y; //Output: 12 1
While this line outputs the expected value of x.
Thanks in advance.
c++ increment post-increment decrement pre-increment
This question already has an answer here:
Undefined behavior and sequence points
5 answers
Unexpected order of evaluation (compiler bug?) [duplicate]
3 answers
Hi I am currently studying for my first exam in C++ programming and I am having this issue:
int x = 12;
int y = 2;
cout << x++ <<" "<< --x; //Output: 11 12
I expected the output to be: 11 11, because 'cout' goes from right to left so the pre-decrement on x (--x) should decrement the value of x, and x++ wouldn't print out 12 because it is post-decrement. Is this an example of undefined behaviour?
cout << x++ << " " << --y; //Output: 12 1
While this line outputs the expected value of x.
Thanks in advance.
This question already has an answer here:
Undefined behavior and sequence points
5 answers
Unexpected order of evaluation (compiler bug?) [duplicate]
3 answers
c++ increment post-increment decrement pre-increment
c++ increment post-increment decrement pre-increment
asked Nov 15 '18 at 15:24
Mirsad HasicMirsad Hasic
1
1
marked as duplicate by CoryKramer
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 15:25
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by CoryKramer
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 15:25
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
"because 'cout' goes from right to left" nope, because you don't have any sequence points between those operations
– CoryKramer
Nov 15 '18 at 15:25
add a comment |
1
"because 'cout' goes from right to left" nope, because you don't have any sequence points between those operations
– CoryKramer
Nov 15 '18 at 15:25
1
1
"because 'cout' goes from right to left" nope, because you don't have any sequence points between those operations
– CoryKramer
Nov 15 '18 at 15:25
"because 'cout' goes from right to left" nope, because you don't have any sequence points between those operations
– CoryKramer
Nov 15 '18 at 15:25
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
"because 'cout' goes from right to left" nope, because you don't have any sequence points between those operations
– CoryKramer
Nov 15 '18 at 15:25