Confusion with operators [duplicate] - c++

This question already has answers here:
Undefined behavior and sequence points
(5 answers)
Closed 9 years ago.
int i=c++ + c++;
Where c is also a integer and has a value of 5.
I thought the answer for this one is 12 or 11! But as it turns out it is 10.
Can anyone explain?
Thanks in advance..

It seems to be undefined behavior. See this post for further information:
Undefined behavior and sequence points

Related

Does using reference in ranged for loop count as "reseating reference to a different object"? [duplicate]

This question already has answers here:
Reference referring to multiple objects, how is it possible? [duplicate]
(2 answers)
Why reference const can be re-assigned in for-statement?
(3 answers)
Closed 21 days ago.
for (int& i : array) {
//do something on i
}
Does this count as "reseating reference i to different objects"?
This, appearently, let i refers to array[0] in first iteration, array[1] in second iteration, ..., and so forth.
Edit 1 in response to comment: I know exact what happens in implementation level. I used compiler explorer to see what does this compile to and I know that this looks completely same as other type of iteration (some level of optimization is assumed). This question is more about on the language level, not implementation.

What is the difference between deque.at(0) vs deque[0] [duplicate]

This question already has answers here:
vector::at vs. vector::operator[]
(8 answers)
Closed 7 months ago.
So i have this queue
deque<int> deq1(2,10);
I Have accessed the element using 2 way and both of them return the same value
cout<<deq1[0];
cout<<deq1.at(0);
why did them make a special function to do the same thing or is one way better than the other?
The only difference is that the function at throw an exception if the index is out of range while the operator[] doesn't make any check. You can see the documentation here
https://en.cppreference.com/w/cpp/container/deque/at
https://en.cppreference.com/w/cpp/container/deque/operator_at

A strange output in C++ [duplicate]

This question already has answers here:
Strange numbers when array is not initialized in C++ [duplicate]
(3 answers)
What happens to a declared, uninitialized variable in C? Does it have a value?
(9 answers)
Closed 1 year ago.
I have tried a simple code and found a strange error(wrt me)
it is something like s[10]
now i have put some number of values into this array.t
like s[0]=0;s[1]=1.s[2]=2 and all others are empty.
now i put a for loop to see how it goes and to my surprise after index 2, some random numbers popping up in output and idk why. It should be null and the loop should have exited but here, it gives me some output like 01248766575...
why is it happening? pls do help me if u know

Why are my array values changing? [duplicate]

This question already has answers here:
How does a leading zero change a numeric literal in Java?
(3 answers)
Closed 7 years ago.
I'm trying to initialize an int array, but when I go back to reference it, my values change as you can see here. For example my values {010, 011} are changing to {8,9}. Can anyone tell me why this is happening? Thank you in advance!
Numbers starting with a zero are treated as octal by the compiler.
010 in octal is 8.
Maybe just use 10 to initialise the values.
By prefixing the 10 with 0, you are telling the compiler that it is an octal number(base-8 number). To solve this, simply initialize your values as {10,11}

The Unpredictablilty of the Order of Evaluation of Subexpressions [duplicate]

This question already has answers here:
Undefined behavior and sequence points
(5 answers)
Multiple increment operators in single statement [duplicate]
(5 answers)
Closed 9 years ago.
Please tell me what this line will print in c++
int a = 5;
cout<<++a <<" " <<++a <<" " <<++a <<endl;
in the book "Schaum's programming with c++" it is given that it will proceed from right to left and output will be
8 7 6
but I am getting output as
8 8 8
Please explain, is there any modification in the C++ language after the book was written?
It's undefined behavior; you could get any results, your program could
crash, or send an insulting letter to your boss. Any book which has this as an example, and specifies some specific output for it, should be thrown in the trash; the author doesn't know C++;